Conflict Between Spatie Laravel Permission Package and Laravel Policies #2687
Unanswered
najeeb-anwari
asked this question in
Q&A
Replies: 1 comment
-
I'm curious: if you downgrade from the latest version 6 to the latest version 5 ( composer |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Conflict Between Spatie Laravel Permission Package and Laravel Policies
Summary
After installing the Spatie Laravel Permission package, my existing Laravel policy-based authorization is encountering conflicts. Specifically, the
Gate::authorize('view', $teamMember)
method, which previously worked, now triggers an error indicating that there is no role namedview
for guardweb
.Error Message
"There is no role named view for guard web.",
"exception": "Spatie\Permission\Exceptions\RoleDoesNotExist",
"file": "C:\laragon\www\chat\vendor\spatie\laravel-permission\src\Exceptions\RoleDoesNotExist.php",
Steps to Reproduce
AuthServiceProvider
.Gate::authorize('view', $teamMember)
method in a controller.Expected Behavior
The
Gate::authorize('view', $teamMember)
method should utilize Laravel's built-in policies and not attempt to find a Spatie role or permission namedview
.Actual Behavior
Instead of using the Laravel policy, the
Gate::authorize('view', $teamMember)
method is attempting to find a Spatie role or permission namedview
, resulting in an error.Relevant Code
AuthServiceProvider:
TeamMemberPolicy:
Controller Method:
Additional Information
-This issue only started occurring after the installation of the Spatie package.
Any assistance or guidance on how to resolve this conflict would be greatly appreciated. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions