1
|
|
|
<?php namespace Modules\Blog\Entities; |
2
|
|
|
|
3
|
|
|
use Dimsav\Translatable\Translatable; |
4
|
|
|
use Illuminate\Database\Eloquent\Builder; |
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Laracasts\Presenter\PresentableTrait; |
7
|
|
|
use Modules\Media\Support\Traits\MediaRelation; |
8
|
|
|
|
9
|
|
|
class Post extends Model |
10
|
|
|
{ |
11
|
|
|
use Translatable, MediaRelation, PresentableTrait; |
12
|
|
|
|
13
|
|
|
public $translatedAttributes = ['title', 'slug', 'content']; |
14
|
|
|
protected $fillable = ['category_id', 'status', 'title', 'slug', 'content']; |
15
|
|
|
protected $table = 'blog__posts'; |
16
|
|
|
protected $presenter = 'Modules\Blog\Presenters\PostPresenter'; |
17
|
|
|
protected $casts = [ |
18
|
|
|
'status' => 'int', |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
public function category() |
22
|
|
|
{ |
23
|
|
|
return $this->hasOne('Modules\Blog\Entities\Category'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function tags() |
27
|
|
|
{ |
28
|
|
|
return $this->belongsToMany('Modules\Blog\Entities\Tag', 'blog__post_tag'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Check if the post is in draft |
33
|
|
|
* @param Builder $query |
34
|
|
|
* @return bool |
35
|
|
|
*/ |
36
|
|
|
public function scopeDraft(Builder $query) |
37
|
|
|
{ |
38
|
|
|
return (bool) $query->whereStatus(0); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Check if the post is pending review |
43
|
|
|
* @param Builder $query |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
|
|
public function scopePending(Builder $query) |
47
|
|
|
{ |
48
|
|
|
return (bool) $query->whereStatus(1); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Check if the post is published |
53
|
|
|
* @param Builder $query |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
public function scopePublished(Builder $query) |
57
|
|
|
{ |
58
|
|
|
return (bool) $query->whereStatus(2); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Check if the post is unpublish |
63
|
|
|
* @param Builder $query |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
|
|
public function scopeUnpublished(Builder $query) |
67
|
|
|
{ |
68
|
|
|
return (bool) $query->whereStatus(3); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|