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