ldc-doux/app/Models/User.php
2022-08-29 17:23:10 +02:00

77 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use App\Enums\Role;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use Kwaadpepper\Enum\Traits\CastsEnums;
class User extends Authenticatable
{
use HasFactory;
use Notifiable;
use CastsEnums;
/**
* Map attribute names to enum classes.
*
* @var array
*/
public $enumCasts = [
'role' => Role::class
];
/**
* The attributes that are mass assignable.
*
* @var string[]
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function boot()
{
static::creating(function (User $user) {
if (Hash::needsRehash($user->password)) {
$user->password = Hash::make($user->password);
}
});
static::updating(function (User $user) {
if (Hash::needsRehash($user->password)) {
$user->password = Hash::make($user->password);
}
});
parent::boot();
}
}