for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Chriscreate\Blog\Traits\Post;
trait PostAttributes
{
public function getTagsCountAttribute()
return $this->tags->count();
tags
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
public function isPublished()
return $this->status == self::PUBLISHED;
status
public function isNotPublished()
return $this->status == self::DRAFT
|| $this->status == self::SCHEDULED;
public function getTimeToReadAttribute()
$word_count = str_word_count(strip_tags($this->content));
content
$minutes = floor($word_count / 200);
$seconds = floor($word_count % 200 / (200 / 60));
$str_minutes = ($minutes == 1) ? 'minute' : 'minutes';
$str_seconds = ($seconds == 1) ? 'second' : 'seconds';
if ($minutes == 0) {
return "{$seconds} {$str_seconds}";
return "{$minutes} {$str_minutes}, {$seconds} {$str_seconds}";
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: