json(['error'=>'Record not found'],400); } return parent::render($request, $exception); } protected function unauthenticated($request, AuthenticationException $exception) { if ($request->expectsJson()) { return response()->json(['error' => 'Unauthenticated.'], 401); } $guard = array_get($exception->guards(), 0); switch ($guard) { case 'contact': $login = 'contact.login'; break; case 'user': $login = 'login'; break; default: $login = 'default'; break; } return redirect()->guest(route($login)); } }