improvements

This commit is contained in:
Mark Gregory
2026-08-26 09:04:25 +01:00
parent 5844aeb621
commit 53a11ae0c7
13 changed files with 479 additions and 36 deletions
+25
View File
@@ -13,6 +13,8 @@ use Illuminate\Support\Str;
use Laravel\Fortify\Contracts\PasskeyUser;
use Laravel\Fortify\PasskeyAuthenticatable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Modules\UserManagement\Models\Role;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
/**
* @property int $id
@@ -48,6 +50,29 @@ class User extends Authenticatable implements PasskeyUser
: $initials;
}
public function roles(): BelongsToMany
{
return $this->belongsToMany(
Role::class,
'user_management_role_user',
'user_id',
'role_id'
);
}
public function hasRole(string $role): bool
{
return $this->roles()->where('slug', $role)->exists();
}
public function hasPermission(string $permission): bool
{
return $this->roles()
->whereHas('permissions', static fn ($query) => $query->where('slug', $permission))
->exists();
}
public function isHelpdeskAdmin(): bool
{
return (bool) $this->helpdesk_admin;