hasRole($role)) { return $next($request); } } throw new UnauthorizedHttpException('Unauthorized: You do not have the required role.'); } }