60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use App\Enums\Role;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
|
use HasFactory, Notifiable;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'username',
|
|
'email',
|
|
'password',
|
|
'is_active',
|
|
'must_change_pw',
|
|
'role',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
'is_active' => 'boolean',
|
|
'must_change_pw' => 'boolean',
|
|
'role' => Role::class,
|
|
];
|
|
|
|
/** Quick helper: check if user is admin */
|
|
public function isAdmin(): bool
|
|
{
|
|
return $this->role === Role::Admin;
|
|
}
|
|
|
|
public function twoFactorMethods()
|
|
{
|
|
return $this->hasMany(\App\Models\TwoFactorMethod::class);
|
|
}
|
|
|
|
public function twoFactorEnabled(): bool
|
|
{
|
|
return $this->twoFactorMethods()->where('enabled', true)->exists();
|
|
}
|
|
|
|
public function twoFactorMethod(string $method): ?\App\Models\TwoFactorMethod
|
|
{
|
|
return $this->twoFactorMethods()->where('method', $method)->first();
|
|
}
|
|
|
|
}
|