作者会话的 Laravel 更改重定向部分过期
Posted
技术标签:
【中文标题】作者会话的 Laravel 更改重定向部分过期【英文标题】:Laravel Change Redirection part if the Auth's session expires 【发布时间】:2017-03-15 22:46:59 【问题描述】:当会话到期时,我的用户被重定向到/login
,但是他们应该被重定向到/backoffice/login
,有谁知道我可以在哪个文件中更改重定向部分?
【问题讨论】:
严肃的问题,为什么这会受到如此多的反对?因为它不包含代码?我认为这个问题不需要代码。 【参考方案1】:您的异常处理程序负责接收所有未经身份验证的请求并以您需要的方式处理它们。
它看起来像这样:
app/Exceptions/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');
来调整重定向
【讨论】:
以上是关于作者会话的 Laravel 更改重定向部分过期的主要内容,如果未能解决你的问题,请参考以下文章
Spring Security:会话过期而不重定向到过期网址?