1 | <?php namespace Arcanesoft\Blog\Models; |
||
25 | class Category extends AbstractModel |
||
26 | { |
||
27 | /* ----------------------------------------------------------------- |
||
28 | | Traits |
||
29 | | ----------------------------------------------------------------- |
||
30 | */ |
||
31 | |||
32 | use SoftDeletes, |
||
33 | HasTranslations; |
||
34 | |||
35 | /* ----------------------------------------------------------------- |
||
36 | | Properties |
||
37 | | ----------------------------------------------------------------- |
||
38 | */ |
||
39 | |||
40 | /** |
||
41 | * The database table used by the model |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $table = 'categories'; |
||
46 | |||
47 | /** |
||
48 | * The attributes that are mass assignable |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $fillable = ['name', 'slug']; |
||
53 | |||
54 | /** |
||
55 | * The attributes that should be mutated to dates. |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $dates = ['deleted_at']; |
||
60 | |||
61 | /** |
||
62 | * The attributes that should be cast to native types. |
||
63 | * |
||
64 | * @var array |
||
65 | */ |
||
66 | protected $casts = [ |
||
67 | 'id' => 'integer', |
||
68 | ]; |
||
69 | |||
70 | /* ----------------------------------------------------------------- |
||
71 | | Relationships |
||
72 | | ----------------------------------------------------------------- |
||
73 | */ |
||
74 | |||
75 | /** |
||
76 | * Relationship with posts. |
||
77 | * |
||
78 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
79 | */ |
||
80 | public function posts() |
||
84 | |||
85 | /* ----------------------------------------------------------------- |
||
86 | | Getters & Setters |
||
87 | | ----------------------------------------------------------------- |
||
88 | */ |
||
89 | |||
90 | /** |
||
91 | * Set the name attribute. |
||
92 | * |
||
93 | * @param string $name |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | public function setNameAttribute($name) |
||
101 | |||
102 | /** |
||
103 | * Set the slug attribute. |
||
104 | * |
||
105 | * @param string $name |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | public function setSlugAttribute($name) |
||
113 | |||
114 | /** |
||
115 | * Get the translatable attributes. |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | public function getTranslatableAttributes() |
||
123 | |||
124 | /* ----------------------------------------------------------------- |
||
125 | | Main Methods |
||
126 | | ----------------------------------------------------------------- |
||
127 | */ |
||
128 | |||
129 | /** |
||
130 | * Create a new category. |
||
131 | * |
||
132 | * @param array $attributes |
||
133 | * |
||
134 | * @return self |
||
135 | */ |
||
136 | public static function createOne(array $attributes) |
||
143 | |||
144 | /** |
||
145 | * Update the current category. |
||
146 | * |
||
147 | * @param array $attributes |
||
148 | * |
||
149 | * @return self |
||
150 | */ |
||
151 | public function updateOne(array $attributes) |
||
157 | |||
158 | /** |
||
159 | * Get the categories options for select input. |
||
160 | * |
||
161 | * @param bool $placeholder |
||
162 | * |
||
163 | * @return \Illuminate\Database\Eloquent\Collection |
||
164 | */ |
||
165 | public static function getSelectOptions($placeholder = true) |
||
180 | |||
181 | /* ----------------------------------------------------------------- |
||
182 | | Check Methods |
||
183 | | ----------------------------------------------------------------- |
||
184 | */ |
||
185 | |||
186 | /** |
||
187 | * Check if category has posts. |
||
188 | * |
||
189 | * @return bool |
||
190 | */ |
||
191 | public function hasPosts() |
||
195 | |||
196 | /** |
||
197 | * Check if the category is deletable. |
||
198 | * |
||
199 | * @return bool |
||
200 | */ |
||
201 | public function isDeletable() |
||
205 | |||
206 | /* ----------------------------------------------------------------- |
||
207 | | Other Methods |
||
208 | | ----------------------------------------------------------------- |
||
209 | */ |
||
210 | |||
211 | /** |
||
212 | * Clear the cached categories. |
||
213 | */ |
||
214 | public static function clearCache() |
||
218 | |||
219 | /** |
||
220 | * Fill the model with an array of attributes. |
||
221 | * |
||
222 | * @param array $attributes |
||
223 | * |
||
224 | * @return self |
||
225 | */ |
||
226 | protected function populate(array $attributes) |
||
236 | } |
||
237 |