1 | <?php namespace Arcanesoft\Blog\Models; |
||
29 | class Post extends Model |
||
30 | { |
||
31 | /* ------------------------------------------------------------------------------------------------ |
||
32 | | Traits |
||
33 | | ------------------------------------------------------------------------------------------------ |
||
34 | */ |
||
35 | use SoftDeletes; |
||
36 | |||
37 | /* ------------------------------------------------------------------------------------------------ |
||
38 | | Properties |
||
39 | | ------------------------------------------------------------------------------------------------ |
||
40 | */ |
||
41 | /** |
||
42 | * The database table used by the model |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $table = 'posts'; |
||
47 | |||
48 | /** |
||
49 | * The attributes that are mass assignable |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $fillable = [ |
||
54 | 'author_id', 'category_id', 'title', 'excerpt', 'content', 'status', 'publish_date' |
||
55 | ]; |
||
56 | |||
57 | /** |
||
58 | * Set or unset the timestamps for the model |
||
59 | * |
||
60 | * @var bool |
||
61 | */ |
||
62 | public $timestamps = true; |
||
63 | |||
64 | /** |
||
65 | * The attributes that should be mutated to dates. |
||
66 | * |
||
67 | * @var array |
||
68 | */ |
||
69 | protected $dates = ['publish_date', 'deleted_at']; |
||
70 | |||
71 | /** |
||
72 | * The attributes that should be casted to native types. |
||
73 | * |
||
74 | * @var array |
||
75 | */ |
||
76 | protected $casts = [ |
||
77 | 'author_id' => 'integer', |
||
78 | 'category_id' => 'integer', |
||
79 | ]; |
||
80 | |||
81 | /* ------------------------------------------------------------------------------------------------ |
||
82 | | Relationships |
||
83 | | ------------------------------------------------------------------------------------------------ |
||
84 | */ |
||
85 | /** |
||
86 | * Relationship with author. |
||
87 | * |
||
88 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
89 | */ |
||
90 | public function author() |
||
94 | |||
95 | /** |
||
96 | * Relationship with category. |
||
97 | * |
||
98 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
99 | */ |
||
100 | public function category() |
||
104 | |||
105 | /** |
||
106 | * Relationship with tags. |
||
107 | * |
||
108 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
109 | */ |
||
110 | public function tags() |
||
114 | |||
115 | /* ------------------------------------------------------------------------------------------------ |
||
116 | | Getters & Setters |
||
117 | | ------------------------------------------------------------------------------------------------ |
||
118 | */ |
||
119 | /** |
||
120 | * Set the title attribute. |
||
121 | * |
||
122 | * @param string $title |
||
123 | */ |
||
124 | public function setTitleAttribute($title) |
||
129 | |||
130 | /** |
||
131 | * Get the status name attribute. |
||
132 | * |
||
133 | * @return null|string |
||
134 | */ |
||
135 | public function getStatusNameAttribute() |
||
139 | |||
140 | /* ------------------------------------------------------------------------------------------------ |
||
141 | | Main Functions |
||
142 | | ------------------------------------------------------------------------------------------------ |
||
143 | */ |
||
144 | /** |
||
145 | * Create a post. |
||
146 | * |
||
147 | * @param array $inputs |
||
148 | * |
||
149 | * @return bool |
||
150 | */ |
||
151 | public function createOne(array $inputs) |
||
166 | |||
167 | /** |
||
168 | * Create a post. |
||
169 | * |
||
170 | * @param array $inputs |
||
171 | * |
||
172 | * @return bool|int |
||
173 | */ |
||
174 | public function updateOne(array $inputs) |
||
187 | |||
188 | /* ------------------------------------------------------------------------------------------------ |
||
189 | | Check Functions |
||
190 | | ------------------------------------------------------------------------------------------------ |
||
191 | */ |
||
192 | /** |
||
193 | * Check if the post's status is "draft". |
||
194 | * |
||
195 | * @return bool |
||
196 | */ |
||
197 | public function isDraft() |
||
201 | |||
202 | /** |
||
203 | * Check if the post's status is "published". |
||
204 | * |
||
205 | * @return bool |
||
206 | */ |
||
207 | public function isPublished() |
||
211 | } |
||
212 |