guard($guard)->guest()) { throw UnauthorizedException::notLoggedIn(); } $route = request()->route()->getName(); if (app('auth')->guard($guard)->user()->can($route)) { return $next($request); } throw UnauthorizedException::forPermissions((array) $route); } }