*/ protected $fillable = [ 'firstname', 'lastname', 'email', 'email_verified_at', 'password', 'role', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', 'role' => UserRolesEnum::class ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted(): void { // * EVENT CLOSURES. static::creating(function (self $model) { self::updatePassword($model); }); static::updating(function (self $model) { self::updatePassword($model); }); } // * METHODS /** * Update password. * * @param self $model * @return void */ private static function updatePassword(self $model): void { if (Hash::needsRehash($model->password)) { $model->password = Hash::make($model->password); } } // * RELATIONSHIPS /** * MorphToMany directories relation. * * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ public function directories(): \Illuminate\Database\Eloquent\Relations\MorphToMany { return $this->morphToMany(Directory::class, 'directorables'); } }