1 | <?php namespace Arcanesoft\Blog\Models; |
||
22 | class Category extends AbstractModel |
||
23 | { |
||
24 | /* ----------------------------------------------------------------- |
||
25 | | Traits |
||
26 | | ----------------------------------------------------------------- |
||
27 | */ |
||
28 | |||
29 | use SoftDeletes; |
||
30 | |||
31 | /* ----------------------------------------------------------------- |
||
32 | | Properties |
||
33 | | ----------------------------------------------------------------- |
||
34 | */ |
||
35 | |||
36 | /** |
||
37 | * The database table used by the model |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $table = 'categories'; |
||
42 | |||
43 | /** |
||
44 | * The attributes that are mass assignable |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $fillable = ['name']; |
||
49 | |||
50 | /** |
||
51 | * The attributes that should be mutated to dates. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $dates = ['deleted_at']; |
||
56 | |||
57 | /** |
||
58 | * The attributes that should be cast to native types. |
||
59 | * |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $casts = [ |
||
63 | 'id' => 'integer', |
||
64 | ]; |
||
65 | |||
66 | /* ----------------------------------------------------------------- |
||
67 | | Relationships |
||
68 | | ----------------------------------------------------------------- |
||
69 | */ |
||
70 | |||
71 | /** |
||
72 | * Relationship with posts. |
||
73 | * |
||
74 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
75 | */ |
||
76 | public function posts() |
||
80 | |||
81 | /* ----------------------------------------------------------------- |
||
82 | | Getters & Setters |
||
83 | | ----------------------------------------------------------------- |
||
84 | */ |
||
85 | |||
86 | /** |
||
87 | * Set the name attribute. |
||
88 | * |
||
89 | * @param string $name |
||
90 | */ |
||
91 | public function setNameAttribute($name) |
||
96 | |||
97 | /* ----------------------------------------------------------------- |
||
98 | | Main Methods |
||
99 | | ----------------------------------------------------------------- |
||
100 | */ |
||
101 | |||
102 | /** |
||
103 | * Create a new category. |
||
104 | * |
||
105 | * @param array $inputs |
||
106 | * |
||
107 | * @return self |
||
108 | */ |
||
109 | public static function createOne(array $inputs) |
||
117 | |||
118 | /** |
||
119 | * Get the categories options for select input. |
||
120 | * |
||
121 | * @param bool $placeholder |
||
122 | * |
||
123 | * @return \Illuminate\Database\Eloquent\Collection |
||
124 | */ |
||
125 | public static function getSelectOptions($placeholder = true) |
||
136 | |||
137 | /* ----------------------------------------------------------------- |
||
138 | | Check Methods |
||
139 | | ----------------------------------------------------------------- |
||
140 | */ |
||
141 | |||
142 | /** |
||
143 | * Check if category has posts. |
||
144 | * |
||
145 | * @return bool |
||
146 | */ |
||
147 | public function hasPosts() |
||
151 | |||
152 | /** |
||
153 | * Check if the category is deletable. |
||
154 | * |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function isDeletable() |
||
161 | |||
162 | /* ----------------------------------------------------------------- |
||
163 | | Other Methods |
||
164 | | ----------------------------------------------------------------- |
||
165 | */ |
||
166 | |||
167 | /** |
||
168 | * Clear the cached categories. |
||
169 | */ |
||
170 | public static function clearCache() |
||
174 | } |
||
175 |