ldc-crm/app/Models/User.php

69 lines
1.5 KiB
PHP
Raw Permalink 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
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',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted()
{
// * 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
}