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

Extract query to getPermissionsWithRoles method. #2316

Merged
merged 1 commit into from
Feb 6, 2023

Conversation

xiCO2k
Copy link
Contributor

@xiCO2k xiCO2k commented Feb 3, 2023

This PR extracts the query a different method.

This will allow to extend the PermissionRegistrar class and change the query.

Example

class PermissionRegistrar extends BasePermissionRegistrar
{
    protected function getPermissionsWithRoles(): Collection
    {
        return $this->getPermissionClass()
            ->withoutGlobalScopes()
            ->select()
            ->with('roles', fn ($query) => $query->withoutGlobalScopes())
            ->get();
    }
}

In this case, I can remove any global scope, applied to the Permission and Role model.

Thanks,
Francisco

@drbyte
Copy link
Collaborator

drbyte commented Feb 6, 2023

Thanks!

@drbyte drbyte merged commit dc76c94 into spatie:main Feb 6, 2023
@xiCO2k xiCO2k deleted the refactor-permission-cache-query branch February 6, 2023 17:42
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