| Total Complexity | 9 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | trait Publishable |
||
| 6 | { |
||
| 7 | public function isPublished() |
||
| 8 | { |
||
| 9 | return (!!$this->published); |
||
| 10 | } |
||
| 11 | |||
| 12 | public function isDraft() |
||
| 13 | { |
||
| 14 | return (!$this->published); |
||
| 15 | } |
||
| 16 | |||
| 17 | public function scopePublished($query) |
||
| 18 | { |
||
| 19 | // Here we widen up the results in case of preview mode and ignore the published scope |
||
| 20 | if (PreviewMode::fromRequest()->check()) { |
||
| 21 | return; |
||
| 22 | } |
||
| 23 | |||
| 24 | $query->where('published', 1); |
||
| 25 | } |
||
| 26 | |||
| 27 | public function scopeDrafted($query) |
||
| 30 | } |
||
| 31 | |||
| 32 | public function publish() |
||
| 33 | { |
||
| 34 | $this->published = 1; |
||
|
|
|||
| 35 | $this->save(); |
||
| 36 | } |
||
| 37 | |||
| 38 | public function draft() |
||
| 39 | { |
||
| 40 | $this->published = 0; |
||
| 41 | $this->save(); |
||
| 42 | } |
||
| 43 | |||
| 44 | public static function getAllPublished() |
||
| 47 | } |
||
| 48 | |||
| 49 | public function scopeSortedByPublished($query) |
||
| 52 | } |
||
| 53 | } |
||
| 54 |