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