2023-03-14 16:17:23 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2023-03-15 09:17:52 +01:00
|
|
|
use App\Enums\AppUserRolesEnum;
|
2023-03-14 16:17:23 +01:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-03-15 10:41:01 +01:00
|
|
|
use Illuminate\Support\Facades\Hash;
|
2023-03-15 09:17:52 +01:00
|
|
|
use Kwaadpepper\Enum\Traits\CastsEnums;
|
2023-03-14 16:17:23 +01:00
|
|
|
|
|
|
|
|
class AppUser extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
2023-03-15 09:17:52 +01:00
|
|
|
use CastsEnums;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* cast enum
|
|
|
|
|
* @var string[]
|
|
|
|
|
*/
|
|
|
|
|
protected $enumCasts = [
|
|
|
|
|
'role' => AppUserRolesEnum::class
|
|
|
|
|
];
|
2023-03-15 10:41:01 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* fillable
|
|
|
|
|
* @var string[]
|
|
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'lastname',
|
|
|
|
|
'firstname',
|
|
|
|
|
'email',
|
|
|
|
|
'password',
|
|
|
|
|
'authorizedFolders',
|
|
|
|
|
'role',
|
|
|
|
|
'status',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform any actions required after the model boots.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::creating(function (self $model) {
|
|
|
|
|
$model->lastname = strtoupper($model->lastname);
|
|
|
|
|
$model->firstname = ucfirst(strtolower($model->firstname));
|
|
|
|
|
$model->password = Hash::make($model->password);
|
|
|
|
|
});
|
|
|
|
|
static::updating(function (self $model) {
|
|
|
|
|
$model->lastname = strtoupper($model->lastname);
|
|
|
|
|
$model->firstname = ucfirst(strtolower($model->firstname));
|
|
|
|
|
if (Hash::needsRehash($model->password)) {
|
|
|
|
|
$model->password = Hash::make($model->password);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-03-14 16:17:23 +01:00
|
|
|
}
|