You have to define your route like this
Route::get('/users', [UsersContoller::class, 'index'])->middleware('checkUserPermissions:view-users');
And you have to update your middleware handle function to
public function handle(Request $request, Closure $next, $permission)
{
// Check user permissions
if (!$this->hasPermissionTo($permission)) {
return redirect('/')->with('error', 'You do not have permission to access to this section of the application');
}
return $next($request);
}
Hope, this will help you.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community