1 | <?php |
||
37 | abstract class User extends Model implements AuthenticatableContract, AuthenticatableTwoFactorContract, AuthorizableContract, CanResetPasswordContract, CanVerifyEmailContract, CanVerifyPhoneContract, HasMedia |
||
|
|||
38 | { |
||
39 | // @TODO: Strangely, this issue happens only here!!! |
||
40 | // Duplicate trait usage to fire attached events for cache |
||
41 | // flush before other events in other traits specially HasActivity, |
||
42 | // otherwise old cached queries used and no changelog recorded on update. |
||
43 | use CacheableEloquent; |
||
44 | use Taggable; |
||
45 | use Auditable; |
||
46 | use Notifiable; |
||
47 | use HasActivity; |
||
48 | use HashidsTrait; |
||
49 | use Authorizable; |
||
50 | use HasHashables; |
||
51 | use HasMediaTrait; |
||
52 | use CanVerifyEmail; |
||
53 | use CanVerifyPhone; |
||
54 | use Authenticatable; |
||
55 | use ValidatingTrait; |
||
56 | use CanResetPassword; |
||
57 | use HasSocialAttributes; |
||
58 | use HasRolesAndAbilities; |
||
59 | use AuthenticatableTwoFactor; |
||
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | protected $fillable = [ |
||
65 | 'username', |
||
66 | 'password', |
||
67 | 'two_factor', |
||
68 | 'email', |
||
69 | 'email_verified', |
||
70 | 'email_verified_at', |
||
71 | 'phone', |
||
72 | 'phone_verified', |
||
73 | 'phone_verified_at', |
||
74 | 'given_name', |
||
75 | 'family_name', |
||
76 | 'title', |
||
77 | 'organization', |
||
78 | 'country_code', |
||
79 | 'language_code', |
||
80 | 'birthday', |
||
81 | 'gender', |
||
82 | 'social', |
||
83 | 'is_active', |
||
84 | 'last_activity', |
||
85 | 'abilities', |
||
86 | 'roles', |
||
87 | 'tags', |
||
88 | ]; |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | protected $casts = [ |
||
94 | 'username' => 'string', |
||
95 | 'password' => 'string', |
||
96 | 'two_factor' => 'json', |
||
97 | 'email' => 'string', |
||
98 | 'email_verified' => 'boolean', |
||
99 | 'email_verified_at' => 'datetime', |
||
100 | 'phone' => 'string', |
||
101 | 'phone_verified' => 'boolean', |
||
102 | 'phone_verified_at' => 'datetime', |
||
103 | 'given_name' => 'string', |
||
104 | 'family_name' => 'string', |
||
105 | 'title' => 'string', |
||
106 | 'organization' => 'string', |
||
107 | 'country_code' => 'string', |
||
108 | 'language_code' => 'string', |
||
109 | 'birthday' => 'string', |
||
110 | 'gender' => 'string', |
||
111 | 'social' => 'array', |
||
112 | 'is_active' => 'boolean', |
||
113 | 'last_activity' => 'datetime', |
||
114 | 'deleted_at' => 'datetime', |
||
115 | ]; |
||
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | protected $hidden = [ |
||
121 | 'password', |
||
122 | 'two_factor', |
||
123 | 'remember_token', |
||
124 | ]; |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | protected $observables = [ |
||
130 | 'validating', |
||
131 | 'validated', |
||
132 | ]; |
||
133 | |||
134 | /** |
||
135 | * The attributes to be encrypted before saving. |
||
136 | * |
||
137 | * @var array |
||
138 | */ |
||
139 | protected $hashables = [ |
||
140 | 'password', |
||
141 | ]; |
||
142 | |||
143 | /** |
||
144 | * The default rules that the model will validate against. |
||
145 | * |
||
146 | * @var array |
||
147 | */ |
||
148 | protected $rules = []; |
||
149 | |||
150 | /** |
||
151 | * Whether the model should throw a |
||
152 | * ValidationException if it fails validation. |
||
153 | * |
||
154 | * @var bool |
||
155 | */ |
||
156 | protected $throwValidationExceptions = true; |
||
157 | |||
158 | /** |
||
159 | * Indicates whether to log only dirty attributes or all. |
||
160 | * |
||
161 | * @var bool |
||
162 | */ |
||
163 | protected static $logOnlyDirty = true; |
||
164 | |||
165 | /** |
||
166 | * The attributes that are logged on change. |
||
167 | * |
||
168 | * @var array |
||
169 | */ |
||
170 | protected static $logFillable = true; |
||
171 | |||
172 | /** |
||
173 | * The attributes that are ignored on change. |
||
174 | * |
||
175 | * @var array |
||
176 | */ |
||
177 | protected static $ignoreChangedAttributes = [ |
||
178 | 'password', |
||
179 | 'two_factor', |
||
180 | 'email_verified_at', |
||
181 | 'phone_verified_at', |
||
182 | 'last_activity', |
||
183 | 'created_at', |
||
184 | 'updated_at', |
||
185 | 'deleted_at', |
||
186 | ]; |
||
187 | |||
188 | /** |
||
189 | * Register media collections. |
||
190 | * |
||
191 | * @return void |
||
192 | */ |
||
193 | public function registerMediaCollections(): void |
||
198 | |||
199 | /** |
||
200 | * Attach the given abilities to the model. |
||
201 | * |
||
202 | * @param mixed $abilities |
||
203 | * |
||
204 | * @return void |
||
205 | */ |
||
206 | public function setAbilitiesAttribute($abilities): void |
||
220 | |||
221 | /** |
||
222 | * Attach the given roles to the model. |
||
223 | * |
||
224 | * @param mixed $roles |
||
225 | * |
||
226 | * @return void |
||
227 | */ |
||
228 | public function setRolesAttribute($roles): void |
||
242 | |||
243 | /** |
||
244 | * {@inheritdoc} |
||
245 | */ |
||
246 | protected static function boot() |
||
258 | |||
259 | /** |
||
260 | * The user may have many sessions. |
||
261 | * |
||
262 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
263 | */ |
||
264 | public function sessions(): MorphMany |
||
268 | |||
269 | /** |
||
270 | * The user may have many socialites. |
||
271 | * |
||
272 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
273 | */ |
||
274 | public function socialites(): MorphMany |
||
278 | |||
279 | /** |
||
280 | * Route notifications for the authy channel. |
||
281 | * |
||
282 | * @return int|null |
||
283 | */ |
||
284 | public function routeNotificationForAuthy(): ?int |
||
301 | |||
302 | /** |
||
303 | * Get the user's country. |
||
304 | * |
||
305 | * @return \Rinvex\Country\Country |
||
306 | */ |
||
307 | public function getCountryAttribute(): Country |
||
311 | |||
312 | /** |
||
313 | * Get the user's language. |
||
314 | * |
||
315 | * @return \Rinvex\Language\Language |
||
316 | */ |
||
317 | public function getLanguageAttribute(): Language |
||
321 | |||
322 | /** |
||
323 | * Get full name attribute. |
||
324 | * |
||
325 | * @return string |
||
326 | */ |
||
327 | public function getFullNameAttribute(): string |
||
331 | |||
332 | /** |
||
333 | * Activate the user. |
||
334 | * |
||
335 | * @return $this |
||
336 | */ |
||
337 | public function activate() |
||
338 | { |
||
339 | $this->update(['is_active' => true]); |
||
340 | |||
341 | return $this; |
||
342 | } |
||
343 | |||
344 | /** |
||
345 | * Deactivate the user. |
||
346 | * |
||
347 | * @return $this |
||
348 | */ |
||
349 | public function deactivate() |
||
350 | { |
||
351 | $this->update(['is_active' => false]); |
||
352 | |||
353 | return $this; |
||
354 | } |
||
355 | |||
356 | /** |
||
357 | * Get the route key for the model. |
||
358 | * |
||
359 | * @return string |
||
360 | */ |
||
361 | public function getRouteKeyName() |
||
365 | } |
||
366 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.