Skip to content

Commit

Permalink
Merge pull request #2380 from erikn69/patch-14
Browse files Browse the repository at this point in the history
[v6][BC] Fix Role->hasPermissionTo() signature to match HasPermissions trait
  • Loading branch information
drbyte committed Mar 30, 2023
2 parents 5048454 + 045f8de commit 24de04a
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,16 @@ protected static function findByParam(array $params = [])
*
* @throws \Spatie\Permission\Exceptions\GuardDoesNotMatch
*/
public function hasPermissionTo($permission): bool
public function hasPermissionTo($permission, $guardName = null): bool
{
if (config('permission.enable_wildcard_permission', false)) {
return $this->hasWildcardPermission($permission, $this->getDefaultGuardName());
}

if (is_string($permission)) {
$permission = $this->getPermissionClass()::findByName($permission, $this->getDefaultGuardName());
}

if (is_int($permission)) {
$permission = $this->getPermissionClass()::findById($permission, $this->getDefaultGuardName());
if ($this->getWildcardClass()) {
return $this->hasWildcardPermission($permission, $guardName);
}

$permission = $this->filterPermission($permission, $guardName);

if (! $this->getGuardNames()->contains($permission->guard_name)) {
throw GuardDoesNotMatch::create($permission->guard_name, $this->getGuardNames());
throw GuardDoesNotMatch::create($permission->guard_name, $guardName ?? $this->getGuardNames());
}

return $this->permissions->contains($permission->getKeyName(), $permission->getKey());
Expand Down

0 comments on commit 24de04a

Please sign in to comment.