1 | <?php namespace Arcanesoft\Blog\Models; |
||
25 | class Tag extends AbstractModel |
||
26 | { |
||
27 | /* ----------------------------------------------------------------- |
||
28 | | Constants |
||
29 | | ----------------------------------------------------------------- |
||
30 | */ |
||
31 | |||
32 | const SELECT_CACHE_NAME = 'blog::tags.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 = 'tags'; |
||
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 event map for the model. |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $events = [ |
||
74 | 'creating' => TagEvents\TagCreating::class, |
||
75 | 'created' => TagEvents\TagCreated::class, |
||
76 | 'updating' => TagEvents\TagUpdating::class, |
||
77 | 'updated' => TagEvents\TagUpdated::class, |
||
78 | 'saving' => TagEvents\TagSaving::class, |
||
79 | 'saved' => TagEvents\TagSaved::class, |
||
80 | 'deleting' => TagEvents\TagDeleting::class, |
||
81 | 'deleted' => TagEvents\TagDeleted::class, |
||
82 | 'restoring' => TagEvents\TagRestoring::class, |
||
83 | 'restored' => TagEvents\TagRestored::class, |
||
84 | ]; |
||
85 | |||
86 | /* ----------------------------------------------------------------- |
||
87 | | Relationships |
||
88 | | ----------------------------------------------------------------- |
||
89 | */ |
||
90 | |||
91 | /** |
||
92 | * Posts relationship. |
||
93 | * |
||
94 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
95 | */ |
||
96 | public function posts() |
||
100 | |||
101 | /* ----------------------------------------------------------------- |
||
102 | | Getters & Setters |
||
103 | | ----------------------------------------------------------------- |
||
104 | */ |
||
105 | |||
106 | /** |
||
107 | * Set the name attribute. |
||
108 | * |
||
109 | * @param string $name |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | public function setNameAttribute($name) |
||
117 | |||
118 | /** |
||
119 | * Set the slug attribute. |
||
120 | * |
||
121 | * @param string $name |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | public function setSlugAttribute($name) |
||
129 | |||
130 | /** |
||
131 | * Get the translatable attributes. |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | public function getTranslatableAttributes() |
||
139 | |||
140 | /* ----------------------------------------------------------------- |
||
141 | | Main Methods |
||
142 | | ----------------------------------------------------------------- |
||
143 | */ |
||
144 | |||
145 | /** |
||
146 | * Create a new tag. |
||
147 | * |
||
148 | * @param array $attributes |
||
149 | * |
||
150 | * @return self |
||
151 | */ |
||
152 | public static function createOne(array $attributes) |
||
158 | |||
159 | /** |
||
160 | * Update the current tag. |
||
161 | * |
||
162 | * @param array $attributes |
||
163 | * |
||
164 | * @return self |
||
165 | */ |
||
166 | public function updateOne(array $attributes) |
||
172 | |||
173 | /** |
||
174 | * Get the categories options for select input. |
||
175 | * |
||
176 | * @return \Illuminate\Database\Eloquent\Collection |
||
177 | */ |
||
178 | public static function getSelectOptions() |
||
188 | |||
189 | /* ----------------------------------------------------------------- |
||
190 | | Check Methods |
||
191 | | ----------------------------------------------------------------- |
||
192 | */ |
||
193 | |||
194 | /** |
||
195 | * Check if tag has posts. |
||
196 | * |
||
197 | * @return bool |
||
198 | */ |
||
199 | public function hasPosts() |
||
203 | |||
204 | /* ----------------------------------------------------------------- |
||
205 | | Other Methods |
||
206 | | ----------------------------------------------------------------- |
||
207 | */ |
||
208 | |||
209 | /** |
||
210 | * Fill the model with an array of attributes. |
||
211 | * |
||
212 | * @param array $attributes |
||
213 | * |
||
214 | * @return self |
||
215 | */ |
||
216 | protected function populate(array $attributes) |
||
226 | } |
||
227 |