1 | <?php namespace Arcanesoft\Blog\Models; |
||
25 | class Category extends AbstractModel |
||
26 | { |
||
27 | /* ----------------------------------------------------------------- |
||
28 | | Constants |
||
29 | | ----------------------------------------------------------------- |
||
30 | */ |
||
31 | |||
32 | const SELECT_CACHE_NAME = 'blog::categories.select-data'; |
||
33 | |||
34 | /* ----------------------------------------------------------------- |
||
35 | | Traits |
||
36 | | ----------------------------------------------------------------- |
||
37 | */ |
||
38 | |||
39 | use SoftDeletes, |
||
40 | HasTranslations; |
||
41 | |||
42 | /* ----------------------------------------------------------------- |
||
43 | | Properties |
||
44 | | ----------------------------------------------------------------- |
||
45 | */ |
||
46 | |||
47 | /** |
||
48 | * The database table used by the model |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $table = 'categories'; |
||
53 | |||
54 | /** |
||
55 | * The attributes that are mass assignable |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $fillable = ['name', 'slug']; |
||
60 | |||
61 | /** |
||
62 | * The attributes that should be mutated to dates. |
||
63 | * |
||
64 | * @var array |
||
65 | */ |
||
66 | protected $dates = ['deleted_at']; |
||
67 | |||
68 | /** |
||
69 | * The attributes that should be cast to native types. |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $casts = [ |
||
74 | 'id' => 'integer', |
||
75 | ]; |
||
76 | |||
77 | /** |
||
78 | * The event map for the model. |
||
79 | * |
||
80 | * @var array |
||
81 | */ |
||
82 | protected $events = [ |
||
83 | 'creating' => CategoryEvents\CategoryCreating::class, |
||
84 | 'created' => CategoryEvents\CategoryCreated::class, |
||
85 | 'updating' => CategoryEvents\CategoryUpdating::class, |
||
86 | 'updated' => CategoryEvents\CategoryUpdated::class, |
||
87 | 'saving' => CategoryEvents\CategorySaving::class, |
||
88 | 'saved' => CategoryEvents\CategorySaved::class, |
||
89 | 'deleting' => CategoryEvents\CategoryDeleting::class, |
||
90 | 'deleted' => CategoryEvents\CategoryDeleted::class, |
||
91 | 'restoring' => CategoryEvents\CategoryRestoring::class, |
||
92 | 'restored' => CategoryEvents\CategoryRestored::class, |
||
93 | ]; |
||
94 | |||
95 | /* ----------------------------------------------------------------- |
||
96 | | Relationships |
||
97 | | ----------------------------------------------------------------- |
||
98 | */ |
||
99 | |||
100 | /** |
||
101 | * Relationship with posts. |
||
102 | * |
||
103 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
104 | */ |
||
105 | public function posts() |
||
109 | |||
110 | /* ----------------------------------------------------------------- |
||
111 | | Getters & Setters |
||
112 | | ----------------------------------------------------------------- |
||
113 | */ |
||
114 | |||
115 | /** |
||
116 | * Set the name attribute. |
||
117 | * |
||
118 | * @param string $name |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | public function setNameAttribute($name) |
||
126 | |||
127 | /** |
||
128 | * Set the slug attribute. |
||
129 | * |
||
130 | * @param string $name |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | public function setSlugAttribute($name) |
||
138 | |||
139 | /** |
||
140 | * Get the translatable attributes. |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | public function getTranslatableAttributes() |
||
148 | |||
149 | /* ----------------------------------------------------------------- |
||
150 | | Main Methods |
||
151 | | ----------------------------------------------------------------- |
||
152 | */ |
||
153 | |||
154 | /** |
||
155 | * Create a new category. |
||
156 | * |
||
157 | * @param array $attributes |
||
158 | * |
||
159 | * @return self |
||
160 | */ |
||
161 | public static function createOne(array $attributes) |
||
167 | |||
168 | /** |
||
169 | * Update the current category. |
||
170 | * |
||
171 | * @param array $attributes |
||
172 | * |
||
173 | * @return self |
||
174 | */ |
||
175 | public function updateOne(array $attributes) |
||
181 | |||
182 | /** |
||
183 | * Get the categories options for select input. |
||
184 | * |
||
185 | * @param bool $placeholder |
||
186 | * |
||
187 | * @return \Illuminate\Database\Eloquent\Collection |
||
188 | */ |
||
189 | public static function getSelectOptions($placeholder = true) |
||
204 | |||
205 | /* ----------------------------------------------------------------- |
||
206 | | Check Methods |
||
207 | | ----------------------------------------------------------------- |
||
208 | */ |
||
209 | |||
210 | /** |
||
211 | * Check if category has posts. |
||
212 | * |
||
213 | * @return bool |
||
214 | */ |
||
215 | public function hasPosts() |
||
219 | |||
220 | /** |
||
221 | * Check if the category is deletable. |
||
222 | * |
||
223 | * @return bool |
||
224 | */ |
||
225 | public function isDeletable() |
||
229 | |||
230 | /* ----------------------------------------------------------------- |
||
231 | | Other Methods |
||
232 | | ----------------------------------------------------------------- |
||
233 | */ |
||
234 | |||
235 | /** |
||
236 | * Fill the model with an array of attributes. |
||
237 | * |
||
238 | * @param array $attributes |
||
239 | * |
||
240 | * @return self |
||
241 | */ |
||
242 | protected function populate(array $attributes) |
||
252 | } |
||
253 |