From 79e5c832dbc180502f9b798354698d3c0881a8bd Mon Sep 17 00:00:00 2001 From: a6a2f5842 Date: Thu, 19 Jun 2025 11:34:12 +0200 Subject: [PATCH] I syncRoles & hasRole --- src/Traits/HasRoles.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Traits/HasRoles.php b/src/Traits/HasRoles.php index b0fa4e3..2f4b6ec 100644 --- a/src/Traits/HasRoles.php +++ b/src/Traits/HasRoles.php @@ -35,7 +35,6 @@ trait HasRoles } elseif (is_numeric($role)) { $role = config('roles.models.role', \Blax\Roles\Models\Role::class)::find($role); } elseif ($role instanceof Role) { - // use pivot column to avoid ambiguous `id` return $this->roles()->wherePivot('role_id', $role->id)->exists(); } else { throw new \InvalidArgumentException('Role must be a string, numeric ID, or an instance of Role.'); @@ -107,9 +106,15 @@ trait HasRoles $roleModel = config('roles.models.role', \Blax\Roles\Models\Role::class)::find($role); } elseif ($role instanceof Role) { $roleModel = $role; + } elseif (is_object($role) && isset($role->id)) { + $roleModel = config('roles.models.role', \Blax\Roles\Models\Role::class)::find($role->id); + } elseif (is_array($role) && isset($role['id'])) { + $roleModel = config('roles.models.role', \Blax\Roles\Models\Role::class)::find($role['id']); + } else { + throw new \InvalidArgumentException('Role must be a string, numeric ID, or an instance of Role.'); } - if ($roleModel instanceof Role) { + if (@$roleModel instanceof Role) { $roleIds[] = $roleModel->id; } } @@ -135,6 +140,7 @@ trait HasRoles } return false; } + /** * Checks if the memberable has all of the given roles *