91 lines
2.8 KiB
PHP
91 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use App\Domain\Identity\Enums\RoleName;
|
|
use App\Domain\Identity\Models\ExternalIdentity;
|
|
use App\Domain\Identity\Models\Role;
|
|
use App\Domain\Reservations\Models\Reservation;
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Carbon;
|
|
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 string $password
|
|
* @property string|null $two_factor_secret
|
|
* @property string|null $two_factor_recovery_codes
|
|
* @property Carbon|null $two_factor_confirmed_at
|
|
* @property string|null $remember_token
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
*/
|
|
#[Fillable(['uuid', 'name', 'email', 'email_verified_at', 'password', 'department', 'snipe_user_id', 'active', 'last_login_at'])]
|
|
#[Hidden(['password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'])]
|
|
class User extends Authenticatable implements PasskeyUser
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasFactory, HasUuids, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable;
|
|
|
|
/** @return list<string> */
|
|
public function uniqueIds(): array
|
|
{
|
|
return ['uuid'];
|
|
}
|
|
|
|
/** @return BelongsToMany<Role, $this> */
|
|
public function roles(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Role::class);
|
|
}
|
|
|
|
/** @return HasMany<Reservation, $this> */
|
|
public function reservations(): HasMany
|
|
{
|
|
return $this->hasMany(Reservation::class, 'requester_id');
|
|
}
|
|
|
|
/** @return HasMany<ExternalIdentity, $this> */
|
|
public function externalIdentities(): HasMany
|
|
{
|
|
return $this->hasMany(ExternalIdentity::class);
|
|
}
|
|
|
|
public function hasRole(RoleName|string $role): bool
|
|
{
|
|
$name = $role instanceof RoleName ? $role->value : $role;
|
|
|
|
return $this->roles()->where('name', $name)->exists();
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'two_factor_confirmed_at' => 'datetime',
|
|
'active' => 'boolean',
|
|
'last_login_at' => 'datetime',
|
|
];
|
|
}
|
|
}
|