improvements
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user