Completed
Push — master ( 425779...b6e961 )
by Abdelrahman
08:30
created

User::boot()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 1
nop 0
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Fort\Models;
6
7
use Rinvex\Fort\Traits\HasRoles;
8
use Illuminate\Auth\Authenticatable;
9
use Illuminate\Support\Facades\Hash;
10
use Rinvex\Fort\Traits\CanVerifyEmail;
11
use Rinvex\Fort\Traits\CanVerifyPhone;
12
use Watson\Validating\ValidatingTrait;
13
use Illuminate\Database\Eloquent\Model;
14
use Rinvex\Cacheable\CacheableEloquent;
15
use Rinvex\Support\Traits\HasHashables;
16
use Illuminate\Notifications\Notifiable;
17
use Rinvex\Fort\Traits\CanResetPassword;
18
use Rinvex\Fort\Traits\AuthenticatableTwoFactor;
19
use Rinvex\Fort\Contracts\CanVerifyEmailContract;
20
use Rinvex\Fort\Contracts\CanVerifyPhoneContract;
21
use Illuminate\Foundation\Auth\Access\Authorizable;
22
use Rinvex\Fort\Contracts\CanResetPasswordContract;
23
use Rinvex\Fort\Contracts\AuthenticatableTwoFactorContract;
24
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
25
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
26
27
/**
28
 * Rinvex\Fort\Models\User.
29
 *
30
 * @property int                                                                                                            $id
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

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.

Loading history...
31
 * @property string                                                                                                         $username
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

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.

Loading history...
32
 * @property array                                                                                                          $two_factor
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

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.

Loading history...
33
 * @property string                                                                                                         $password
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

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.

Loading history...
34
 * @property string|null                                                                                                    $remember_token
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 characters

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.

Loading history...
35
 * @property string                                                                                                         $email
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 130 characters

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.

Loading history...
36
 * @property int                                                                                                            $email_verified
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 characters

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.

Loading history...
37
 * @property \Carbon\Carbon|null                                                                                            $email_verified_at
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 142 characters

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.

Loading history...
38
 * @property string|null                                                                                                    $phone
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 130 characters

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.

Loading history...
39
 * @property int                                                                                                            $phone_verified
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 characters

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.

Loading history...
40
 * @property \Carbon\Carbon|null                                                                                            $phone_verified_at
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 142 characters

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.

Loading history...
41
 * @property string|null                                                                                                    $name_prefix
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 136 characters

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.

Loading history...
42
 * @property string|null                                                                                                    $first_name
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

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.

Loading history...
43
 * @property string|null                                                                                                    $middle_name
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 136 characters

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.

Loading history...
44
 * @property string|null                                                                                                    $last_name
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

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.

Loading history...
45
 * @property string|null                                                                                                    $name_suffix
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 136 characters

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.

Loading history...
46
 * @property string|null                                                                                                    $job_title
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

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.

Loading history...
47
 * @property string|null                                                                                                    $country_code
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 137 characters

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.

Loading history...
48
 * @property string|null                                                                                                    $language_code
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

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.

Loading history...
49
 * @property \Carbon\Carbon|null                                                                                            $birthday
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

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.

Loading history...
50
 * @property string|null                                                                                                    $gender
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 131 characters

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.

Loading history...
51
 * @property int                                                                                                            $is_active
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

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.

Loading history...
52
 * @property \Carbon\Carbon|null                                                                                            $last_activity
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

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.

Loading history...
53
 * @property \Carbon\Carbon|null                                                                                            $created_at
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

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.

Loading history...
54
 * @property \Carbon\Carbon|null                                                                                            $updated_at
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

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.

Loading history...
55
 * @property \Carbon\Carbon|null                                                                                            $deleted_at
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

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.

Loading history...
56
 * @property \Illuminate\Database\Eloquent\Collection|\Rinvex\Fort\Models\Ability[]                                         $abilities
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

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.

Loading history...
57
 * @property-read \Illuminate\Support\Collection                                                                            $all_abilities
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

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.

Loading history...
58
 * @property-read \Rinvex\Country\Country                                                                                   $country
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

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.

Loading history...
59
 * @property-read \Rinvex\Language\Language                                                                                 $language
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

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.

Loading history...
60
 * @property-read string                                                                                                    $name
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 129 characters

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.

Loading history...
61
 * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

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.

Loading history...
62
 * @property \Illuminate\Database\Eloquent\Collection|\Rinvex\Fort\Models\Role[]                                            $roles
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 130 characters

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.

Loading history...
63
 * @property-read \Illuminate\Database\Eloquent\Collection|\Rinvex\Fort\Models\Session[]                                    $sessions
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

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.

Loading history...
64
 * @property-read \Illuminate\Database\Eloquent\Collection|\Rinvex\Fort\Models\Socialite[]                                  $socialites
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

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.

Loading history...
65
 *
66
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User role($roles)
67
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereBirthday($value)
68
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereCountryCode($value)
69
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereCreatedAt($value)
70
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereDeletedAt($value)
71
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereEmail($value)
72
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereEmailVerified($value)
73
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereEmailVerifiedAt($value)
74
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereFirstName($value)
75
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereGender($value)
76
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereId($value)
77
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereIsActive($value)
78
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereJobTitle($value)
79
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereLanguageCode($value)
80
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereLastActivity($value)
81
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereLastName($value)
82
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereMiddleName($value)
83
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereNamePrefix($value)
84
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereNameSuffix($value)
85
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User wherePassword($value)
86
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User wherePhone($value)
87
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User wherePhoneVerified($value)
88
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User wherePhoneVerifiedAt($value)
89
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereRememberToken($value)
90
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereTwoFactor($value)
91
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereUpdatedAt($value)
92
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Fort\Models\User whereUsername($value)
93
 * @mixin \Eloquent
94
 */
95
class User extends Model implements AuthenticatableContract, AuthenticatableTwoFactorContract, AuthorizableContract, CanResetPasswordContract, CanVerifyEmailContract, CanVerifyPhoneContract
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 189 characters

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.

Loading history...
96
{
97
    use HasRoles;
98
    use Notifiable;
99
    use Authorizable;
100
    use HasHashables;
101
    use CanVerifyEmail;
102
    use CanVerifyPhone;
103
    use Authenticatable;
104
    use ValidatingTrait;
105
    use CanResetPassword;
106
    use CacheableEloquent;
107
    use AuthenticatableTwoFactor;
108
109
    /**
110
     * {@inheritdoc}
111
     */
112
    protected $dates = [
113
        'email_verified_at',
114
        'phone_verified_at',
115
        'birthday',
116
        'last_activity',
117
        'deleted_at',
118
    ];
119
120
    /**
121
     * {@inheritdoc}
122
     */
123
    protected $fillable = [
124
        'username',
125
        'password',
126
        'two_factor',
127
        'email',
128
        'email_verified',
129
        'email_verified_at',
130
        'phone',
131
        'phone_verified',
132
        'phone_verified_at',
133
        'name_prefix',
134
        'first_name',
135
        'middle_name',
136
        'last_name',
137
        'name_suffix',
138
        'job_title',
139
        'country_code',
140
        'language_code',
141
        'birthday',
142
        'gender',
143
        'is_active',
144
        'last_activity',
145
        'abilities',
146
        'roles',
147
    ];
148
149
    /**
150
     * {@inheritdoc}
151
     */
152
    protected $hidden = [
153
        'password',
154
        'two_factor',
155
        'remember_token',
156
    ];
157
158
    /**
159
     * {@inheritdoc}
160
     */
161
    protected $with = ['abilities', 'roles'];
162
163
    /**
164
     * {@inheritdoc}
165
     */
166
    protected $observables = ['validating', 'validated'];
167
168
    /**
169
     * The attributes to be encrypted before saving.
170
     *
171
     * @var array
172
     */
173
    protected $hashables = ['password'];
174
175
    /**
176
     * The default rules that the model will validate against.
177
     *
178
     * @var array
179
     */
180
    protected $rules = [];
181
182
    /**
183
     * Whether the model should throw a
184
     * ValidationException if it fails validation.
185
     *
186
     * @var bool
187
     */
188
    protected $throwValidationExceptions = true;
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $throwValidationExceptions exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
189
190
    /**
191
     * Create a new Eloquent model instance.
192
     *
193
     * @param array $attributes
194
     */
195
    public function __construct(array $attributes = [])
196
    {
197
        parent::__construct($attributes);
198
199
        $this->setTable(config('rinvex.fort.tables.users'));
200
        $this->setRules([
201
            'email' => 'required|email|min:3|max:150|unique:'.config('rinvex.fort.tables.users').',email',
202
            'username' => 'required|alpha_dash|min:3|max:150|unique:'.config('rinvex.fort.tables.users').',username',
203
            'password' => 'sometimes|required|min:'.config('rinvex.fort.password_min_chars'),
204
            'gender' => 'nullable|string|in:male,female',
205
            'phone' => 'nullable|numeric|min:4',
206
        ]);
207
    }
208
209
    /**
210
     * {@inheritdoc}
211
     */
212
    protected static function boot()
213
    {
214
        parent::boot();
215
216
        static::saving(function (self $user) {
217
            foreach (array_intersect($user->getHashables(), array_keys($user->getAttributes())) as $hashable) {
218
                if ($user->isDirty($hashable) && Hash::needsRehash($user->$hashable)) {
219
                    $user->$hashable = Hash::make($user->$hashable);
220
                }
221
            }
222
        });
223
    }
224
225
    /**
226
     * Register a validating user event with the dispatcher.
227
     *
228
     * @param \Closure|string $callback
229
     *
230
     * @return void
231
     */
232
    public static function validating($callback)
233
    {
234
        static::registerModelEvent('validating', $callback);
235
    }
236
237
    /**
238
     * Register a validated user event with the dispatcher.
239
     *
240
     * @param \Closure|string $callback
241
     *
242
     * @return void
243
     */
244
    public static function validated($callback)
245
    {
246
        static::registerModelEvent('validated', $callback);
247
    }
248
249
    /**
250
     * A user may have multiple direct abilities.
251
     *
252
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
253
     */
254
    public function abilities()
255
    {
256
        return $this->belongsToMany(config('rinvex.fort.models.ability'), config('rinvex.fort.tables.ability_user'), 'user_id', 'ability_id')
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 141 characters

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.

Loading history...
257
                    ->withTimestamps();
258
    }
259
260
    /**
261
     * A user may have multiple roles.
262
     *
263
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
264
     */
265
    public function roles()
266
    {
267
        return $this->belongsToMany(config('rinvex.fort.models.role'), config('rinvex.fort.tables.role_user'), 'user_id', 'role_id')
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

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.

Loading history...
268
                    ->withTimestamps();
269
    }
270
271
    /**
272
     * A user may have multiple sessions.
273
     *
274
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
275
     */
276
    public function sessions()
277
    {
278
        return $this->hasMany(config('rinvex.fort.models.session'), 'user_id', 'id');
279
    }
280
281
    /**
282
     * A user may have multiple socialites.
283
     *
284
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
285
     */
286
    public function socialites()
287
    {
288
        return $this->hasMany(config('rinvex.fort.models.socialite'), 'user_id', 'id');
289
    }
290
291
    /**
292
     * Get name attribute.
293
     *
294
     * @return string
295
     */
296
    public function getNameAttribute()
297
    {
298
        $segments = [$this->name_prefix, $this->first_name, $this->middle_name, $this->last_name, $this->name_suffix];
299
300
        return trim(implode(' ', $segments));
301
    }
302
303
    /**
304
     * Get all abilities of the user.
305
     *
306
     * @return \Illuminate\Support\Collection
307
     */
308
    public function getAllAbilitiesAttribute()
309
    {
310
        return $this->abilities->merge($this->roles->pluck('abilities')->collapse());
311
    }
312
313
    /**
314
     * Determine if the user is super admin.
315
     *
316
     * @return bool
317
     */
318
    public function isSuperadmin()
319
    {
320
        return $this->getAllAbilitiesAttribute()->where('resource', 'global')->where('policy', null)->contains('action', 'superadmin');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

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.

Loading history...
321
    }
322
323
    /**
324
     * Determine if the user is protected.
325
     *
326
     * @return bool
327
     */
328
    public function isProtected()
329
    {
330
        return in_array($this->id, config('rinvex.fort.protected.users'));
331
    }
332
333
    /**
334
     * Route notifications for the authy channel.
335
     *
336
     * @return int
337
     */
338
    public function routeNotificationForAuthy()
339
    {
340
        if (! ($authyId = array_get($this->getTwoFactor(), 'phone.authy_id')) && $this->getEmailForVerification() && $this->getPhoneForVerification() && $this->getCountryForVerification()) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 190 characters

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.

Loading history...
341
            $result = app('rinvex.authy.user')->register($this->getEmailForVerification(), preg_replace('/[^0-9]/', '', $this->getPhoneForVerification()), $this->getCountryForVerification());
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 191 characters

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.

Loading history...
342
            $authyId = $result->get('user')['id'];
343
344
            // Prepare required variables
345
            $twoFactor = $this->getTwoFactor();
346
347
            // Update user account
348
            array_set($twoFactor, 'phone.authy_id', $authyId);
349
350
            $this->fill(['two_factor' => $twoFactor])->forceSave();
351
        }
352
353
        return $authyId;
354
    }
355
356
    /**
357
     * Get the user's country.
358
     *
359
     * @return \Rinvex\Country\Country
360
     */
361
    public function getCountryAttribute()
362
    {
363
        return country($this->country_code);
364
    }
365
366
    /**
367
     * Get the user's language.
368
     *
369
     * @return \Rinvex\Language\Language
370
     */
371
    public function getLanguageAttribute()
372
    {
373
        return language($this->language_code);
374
    }
375
376
    /**
377
     * Attach the user roles.
378
     *
379
     * @param mixed $roles
380
     *
381
     * @return void
382
     */
383
    public function setRolesAttribute($roles)
384
    {
385
        static::saved(function (self $model) use ($roles) {
386
            $model->roles()->sync($roles);
387
        });
388
    }
389
390
    /**
391
     * Attach the user abilities.
392
     *
393
     * @param mixed $abilities
394
     *
395
     * @return void
396
     */
397
    public function setAbilitiesAttribute($abilities)
398
    {
399
        static::saved(function (self $model) use ($abilities) {
400
            $model->abilities()->sync($abilities);
401
        });
402
    }
403
}
404