Reputation: 21
I am using Spatie
Permissions for my Laravel
app. I have assigned permissions to a role, and the role to a user.
When I use $user->getAllPermissions()
or $user->getPermissionsViaRoles()
it displays them all in JSON
format.
However, when I am ensuring they have a certain permission before viewing a route using Spatie
middleware (permission/can) it says unauthorized.
Route::get('/admin/users', \App\Http\Livewire\Admin\User\UserList::class)->middleware('permission:view users')->name('admin.users');
I was wondering how I can make it so it knows the permission is assigned through the users role?
It says best practice is to do it how I've done, rather than assigning permissions direct to users.
I've tried using AI, googling, etc and found no answers.
Upvotes: 0
Views: 354
Reputation: 923
are you using the \Illuminate\Auth\Middleware\Authorize::class in your kernal.php? I believe that to be required for using the can middleware.
Upvotes: 0