ldc-crm/app/Models/User.php

70 lines
1.9 KiB
PHP
Raw Normal View History

2020-12-01 17:02:10 +01:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
2020-12-01 17:02:10 +01:00
/**
* @property integer $id Id.
* @property string $lastname Nom.
* @property string $firstname Prénom.
* @property string $email Email.
* @property string $password Mot de passe.
* @property string|null $remember_token Token mot de passe.
* @property-read \Illuminate\Support\Carbon $created_at Created date.
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
*/
2020-12-01 17:02:10 +01:00
class User extends Authenticatable
{
use HasFactory;
use Notifiable;
2020-12-01 17:02:10 +01:00
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'lastname',
'firstname',
2020-12-01 17:02:10 +01:00
'email',
'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted(): void
{
// * EVENT CLOSURES.
static::creating(function (self $model) {
if (Hash::needsRehash($model->password)) {
$model->password = Hash::make($model->password);
}
$model->remember_token = Str::random(10);
});
static::updating(function (self $model) {
if (Hash::needsRehash($model->password)) {
$model->password = Hash::make($model->password);
}
$model->remember_token = Str::random(10);
});
}
2020-12-01 17:02:10 +01:00
}