| 1 | <?php |
||
| 7 | trait PublishableTrait |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Published an entity. |
||
| 11 | * |
||
| 12 | * @return \Illuminate\Database\Eloquent\Model |
||
| 13 | */ |
||
| 14 | public function publish() |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Published/Unpublished an entity. |
||
| 24 | * |
||
| 25 | * @return \Illuminate\Database\Eloquent\Model |
||
| 26 | */ |
||
| 27 | public function togglePublishedState() |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Unpublished an entity. |
||
| 37 | * |
||
| 38 | * @return \Illuminate\Database\Eloquent\Model |
||
| 39 | */ |
||
| 40 | public function unpublish() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Query scope for published articles. |
||
| 50 | * |
||
| 51 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
| 52 | * @return \Illuminate\Database\Eloquent\Builder |
||
| 53 | */ |
||
| 54 | public function scopePublished($query) : Builder |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Query scope for unpublished articles. |
||
| 61 | * |
||
| 62 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
| 63 | * @return \Illuminate\Database\Eloquent\Builder |
||
| 64 | */ |
||
| 65 | public function scopeUnpublished($query) : Builder |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Check if entity was published. |
||
| 72 | * |
||
| 73 | * @return bool |
||
| 74 | */ |
||
| 75 | public function isPublished() |
||
| 79 | } |
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: