ldc-doux/app/Models/User.php

68 lines
1.4 KiB
PHP
Raw Normal View History

2021-11-18 14:36:06 +01:00
<?php
namespace App\Models;
2021-12-07 23:35:14 +01:00
use App\Enums\Role;
2021-11-18 14:36:06 +01:00
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
2021-12-07 23:35:14 +01:00
use Illuminate\Support\Facades\Hash;
2021-11-18 14:36:06 +01:00
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
2021-12-07 23:35:14 +01:00
use HasFactory;
use Notifiable;
public $castEnums = [
'role' => Role::class
];
2021-11-18 14:36:06 +01:00
/**
* 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',
];
2021-12-07 23:35:14 +01:00
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();
}
2021-11-18 14:36:06 +01:00
}