如果auth&# 39;s会话过期,则更改重定向部分


Laravel Change Redirection part if the Auth's session expires

当会话到期时,我的用户正在重定向到/login,但是他们应该重定向到/backoffice/login,有人知道我可以在哪个文件中更改重定向部分吗?

你的异常处理程序接收所有未经身份验证的请求,并以你需要的方式处理它们。

它看起来像这样:

/app/异常Handler.php

/**
 * Convert an authentication exception into an unauthenticated response.
 *
 * @param  'Illuminate'Http'Request  $request
 * @param  'Illuminate'Auth'AuthenticationException  $exception
 * @return 'Illuminate'Http'Response
 */
protected function unauthenticated($request, AuthenticationException $exception)
{
    if ($request->expectsJson()) {
        return response()->json(['error' => 'Unauthenticated.'], 401);
    }
    return redirect()->guest('login');
}

您可以通过将return redirect()->guest('login');更改为return redirect()->guest('backoffice/login');来调整重定向