Skip to content

Commit

Permalink
Merge pull request #2194 from erikn69/patch-6
Browse files Browse the repository at this point in the history
Fix returning all roles instead of the assigned
  • Loading branch information
drbyte committed Oct 19, 2022
2 parents 5e8b069 + a096b9d commit bc2227c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Traits/HasRoles.php
Expand Up @@ -189,6 +189,8 @@ public function syncRoles(...$roles)
*/
public function hasRole($roles, string $guard = null): bool
{
$this->loadMissing('roles');

if (is_string($roles) && false !== strpos($roles, '|')) {
$roles = $this->convertPipeToArray($roles);
}
Expand Down Expand Up @@ -248,6 +250,8 @@ public function hasAnyRole(...$roles): bool
*/
public function hasAllRoles($roles, string $guard = null): bool
{
$this->loadMissing('roles');

if (is_string($roles) && false !== strpos($roles, '|')) {
$roles = $this->convertPipeToArray($roles);
}
Expand Down Expand Up @@ -282,6 +286,8 @@ public function hasAllRoles($roles, string $guard = null): bool
*/
public function hasExactRoles($roles, string $guard = null): bool
{
$this->loadMissing('roles');

if (is_string($roles) && false !== strpos($roles, '|')) {
$roles = $this->convertPipeToArray($roles);
}
Expand Down Expand Up @@ -311,6 +317,8 @@ public function getDirectPermissions(): Collection

public function getRoleNames(): Collection
{
$this->loadMissing('roles');

return $this->roles->pluck('name');
}

Expand Down

0 comments on commit bc2227c

Please sign in to comment.