I am using the laravel-permission
extension from Spatie for managing user roles and permissions. I have configured users, roles and permissions and it is updated in the database correctly. Now I am trying to protect the routes using role
middleware as follows:
Route::group(['middleware' => ['role:Manager']], function () {
Route::get('/test', function(){
echo "HERE";
die();
});
});
When I access the test
URL, it is always showing 403 Forbidden
error. I have checked the user roles using $user->roles()->pluck('name');
and it is returning the following:
Illuminate\Support\Collection {#1180 ▼
#items: array:1 [▼
0 => "Manager"
]
}
But still I am getting the 403
error. How can I fix this ? I need to add anything to the routes to make the middleware working ?