Prime-Chat/app/Models/User.php

65 lines
1.4 KiB
PHP
Raw Normal View History

2024-12-19 07:21:23 +04:00
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Enums\UserRoleEnum;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
'role'
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
protected function isAdmin(): Attribute
{
return Attribute::make(
get: fn () => UserRoleEnum::tryFrom($this->role) === UserRoleEnum::Admin,
);
}
protected function isEmployee(): Attribute
{
return Attribute::make(
get: fn () => UserRoleEnum::tryFrom($this->role) === UserRoleEnum::Employee,
);
}
}