71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Str;
|
|
use Laravel\Fortify\Contracts\PasskeyUser;
|
|
use Laravel\Fortify\PasskeyAuthenticatable;
|
|
use Laravel\Fortify\TwoFactorAuthenticatable;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property string $email
|
|
* @property Carbon|null $email_verified_at
|
|
* @property bool $helpdesk_agent
|
|
* @property bool $helpdesk_admin
|
|
*/
|
|
#[Fillable(['name', 'email', 'password', 'email_verified_at', 'helpdesk_agent', 'helpdesk_admin'])]
|
|
#[Hidden(['password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'])]
|
|
class User extends Authenticatable implements PasskeyUser
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasFactory, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'helpdesk_agent' => 'boolean',
|
|
'helpdesk_admin' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function initials(): string
|
|
{
|
|
$initials = Str::initials($this->name, true);
|
|
|
|
return Str::length($initials) > 1
|
|
? Str::substr($initials, 0, 1).Str::substr($initials, -1)
|
|
: $initials;
|
|
}
|
|
|
|
public function isHelpdeskAdmin(): bool
|
|
{
|
|
return (bool) $this->helpdesk_admin;
|
|
}
|
|
|
|
public function isHelpdeskAgent(): bool
|
|
{
|
|
return $this->isHelpdeskAdmin() || (bool) $this->helpdesk_agent;
|
|
}
|
|
|
|
public function isAdmin(): bool
|
|
{
|
|
return $this->isHelpdeskAdmin();
|
|
}
|
|
|
|
public function isAgent(): bool
|
|
{
|
|
return $this->isHelpdeskAgent();
|
|
}
|
|
}
|