1 | <?php namespace Arcanesoft\Blog\Models; |
||
39 | class Post extends AbstractModel |
||
40 | { |
||
41 | /* ------------------------------------------------------------------------------------------------ |
||
42 | | Constants |
||
43 | | ------------------------------------------------------------------------------------------------ |
||
44 | */ |
||
45 | const STATUS_DRAFT = 'draft'; |
||
46 | const STATUS_PUBLISHED = 'published'; |
||
47 | |||
48 | /* ------------------------------------------------------------------------------------------------ |
||
49 | | Traits |
||
50 | | ------------------------------------------------------------------------------------------------ |
||
51 | */ |
||
52 | use Seoable, SoftDeletes; |
||
53 | |||
54 | /* ------------------------------------------------------------------------------------------------ |
||
55 | | Properties |
||
56 | | ------------------------------------------------------------------------------------------------ |
||
57 | */ |
||
58 | /** |
||
59 | * The database table used by the model |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $table = 'posts'; |
||
64 | |||
65 | /** |
||
66 | * The attributes that are mass assignable |
||
67 | * |
||
68 | * @var array |
||
69 | */ |
||
70 | protected $fillable = [ |
||
71 | 'author_id', 'category_id', 'title', 'excerpt', 'content', 'published_at' |
||
72 | ]; |
||
73 | |||
74 | /** |
||
75 | * The attributes that should be mutated to dates. |
||
76 | * |
||
77 | * @var array |
||
78 | */ |
||
79 | protected $dates = ['published_at', 'deleted_at']; |
||
80 | |||
81 | /** |
||
82 | * The attributes that should be casted to native types. |
||
83 | * |
||
84 | * @var array |
||
85 | */ |
||
86 | protected $casts = [ |
||
87 | 'author_id' => 'integer', |
||
88 | 'category_id' => 'integer', |
||
89 | 'is_draft' => 'boolean', |
||
90 | ]; |
||
91 | |||
92 | /* ------------------------------------------------------------------------------------------------ |
||
93 | | Scopes |
||
94 | | ------------------------------------------------------------------------------------------------ |
||
95 | */ |
||
96 | /** |
||
97 | * Scope only published posts. |
||
98 | * |
||
99 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
100 | */ |
||
101 | public function scopePublished(Builder $builder) |
||
106 | |||
107 | /** |
||
108 | * Scope only published posts. |
||
109 | * |
||
110 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
111 | * @param int $year |
||
112 | */ |
||
113 | public function scopePublishedAt(Builder $builder, $year) |
||
118 | |||
119 | /* ------------------------------------------------------------------------------------------------ |
||
120 | | Relationships |
||
121 | | ------------------------------------------------------------------------------------------------ |
||
122 | */ |
||
123 | /** |
||
124 | * Author relationship. |
||
125 | * |
||
126 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
127 | */ |
||
128 | public function author() |
||
135 | |||
136 | /** |
||
137 | * Category relationship. |
||
138 | * |
||
139 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
140 | */ |
||
141 | public function category() |
||
145 | |||
146 | /** |
||
147 | * Tags relationship. |
||
148 | * |
||
149 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
150 | */ |
||
151 | public function tags() |
||
155 | |||
156 | /* ------------------------------------------------------------------------------------------------ |
||
157 | | Getters & Setters |
||
158 | | ------------------------------------------------------------------------------------------------ |
||
159 | */ |
||
160 | /** |
||
161 | * Set the title attribute. |
||
162 | * |
||
163 | * @param string $title |
||
164 | */ |
||
165 | public function setTitleAttribute($title) |
||
170 | |||
171 | /** |
||
172 | * Set the content attribute. |
||
173 | * |
||
174 | * @param string $content |
||
175 | */ |
||
176 | public function setContentAttribute($content) |
||
181 | |||
182 | /** |
||
183 | * Get the content attribute. |
||
184 | * |
||
185 | * @return \Illuminate\Support\HtmlString |
||
186 | */ |
||
187 | public function getContentAttribute() |
||
191 | |||
192 | /** |
||
193 | * Set the status attribute. |
||
194 | * |
||
195 | * @param string $content |
||
|
|||
196 | */ |
||
197 | public function setStatusAttribute($status) |
||
201 | |||
202 | /** |
||
203 | * Get the status name attribute. |
||
204 | * |
||
205 | * @return string|null |
||
206 | */ |
||
207 | public function getStatusNameAttribute() |
||
213 | |||
214 | /* ------------------------------------------------------------------------------------------------ |
||
215 | | Main Functions |
||
216 | | ------------------------------------------------------------------------------------------------ |
||
217 | */ |
||
218 | /** |
||
219 | * Create a post. |
||
220 | * |
||
221 | * @param array $inputs |
||
222 | * |
||
223 | * @return bool |
||
224 | */ |
||
225 | public function createOne(array $inputs) |
||
245 | |||
246 | /** |
||
247 | * Create a post. |
||
248 | * |
||
249 | * @param array $inputs |
||
250 | * |
||
251 | * @return bool|int |
||
252 | */ |
||
253 | public function updateOne(array $inputs) |
||
267 | |||
268 | /* ------------------------------------------------------------------------------------------------ |
||
269 | | Check Functions |
||
270 | | ------------------------------------------------------------------------------------------------ |
||
271 | */ |
||
272 | /** |
||
273 | * Check if the post's status is "draft". |
||
274 | * |
||
275 | * @return bool |
||
276 | */ |
||
277 | public function isDraft() |
||
281 | |||
282 | /** |
||
283 | * Check if the post's status is "published". |
||
284 | * |
||
285 | * @return bool |
||
286 | */ |
||
287 | public function isPublished() |
||
291 | |||
292 | /* ------------------------------------------------------------------------------------------------ |
||
293 | | Other Functions |
||
294 | | ------------------------------------------------------------------------------------------------ |
||
295 | */ |
||
296 | /** |
||
297 | * Get the post statuses. |
||
298 | * |
||
299 | * @return \Illuminate\Support\Collection |
||
300 | */ |
||
301 | public static function getStatuses() |
||
307 | |||
308 | /** |
||
309 | * Extract the seo attributes. |
||
310 | * |
||
311 | * @param array $inputs |
||
312 | * |
||
313 | * @return array |
||
314 | */ |
||
315 | protected function extractSeoAttributes(array $inputs) |
||
324 | } |
||
325 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.