【问题标题】:Laravel Change Redirection part if the Auth's session expires作者会话的 Laravel 更改重定向部分过期
【发布时间】:2017-03-15 22:46:59
【问题描述】:

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

【问题讨论】:

  • 严肃的问题,为什么这会受到如此多的反对?因为它不包含代码?我认为这个问题不需要代码。

标签: php laravel session redirect 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'); 来调整重定向

【讨论】:

    猜你喜欢
    • 2014-11-19
    • 2019-05-27
    • 2017-12-13
    • 2015-10-08
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    • 2016-06-22
    • 2015-05-18
    相关资源
    最近更新 更多