Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegate permission filter to another method #2183

Merged
merged 4 commits into from
Oct 19, 2022
Merged

Conversation

angeljqv
Copy link
Contributor

@angeljqv angeljqv commented Sep 21, 2022

This could help with third party customization of the package

It is the same code, only i did move it to his own method, it is NOT A BREAKING CHANGE, it could be helpful
This change is TESTED

Little and marginal optimitations(less duplicity)

$permissionClass = $this->getPermissionClass();
if (is_string($permission)) {
$permission = $permissionClass->findByName(
$permission,
$guardName ?? $this->getDefaultGuardName()
);
}
if (is_int($permission)) {
$permission = $permissionClass->findById(
$permission,
$guardName ?? $this->getDefaultGuardName()
);
}
if (! $permission instanceof Permission) {
throw new PermissionDoesNotExist();
}

$permissionClass = $this->getPermissionClass();
if (is_string($permission)) {
$permission = $permissionClass->findByName($permission, $this->getDefaultGuardName());
}
if (is_int($permission)) {
$permission = $permissionClass->findById($permission, $this->getDefaultGuardName());
}
if (! $permission instanceof Permission) {
throw new PermissionDoesNotExist();
}

@drbyte
Copy link
Collaborator

drbyte commented Oct 19, 2022

Thanks

@drbyte drbyte merged commit 5e8b069 into spatie:main Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants