check($guards)) { return $next($request); } if ($request->ajax() || $request->wantsJson()) { return response('Unauthorized.', 401); } else { return redirect()->guest('login'); } } /** * Determine if the user is logged in to any of the given guards. * * @param array $guards * @return bool */ protected function check(array $guards) { if (empty($guards)) { return Auth::check(); } foreach ($guards as $guard) { if (Auth::guard($guard)->check()) { Auth::shouldUse($guard); return true; } } return false; } }