【问题标题】:Laravel 5.4 logout redirectionLaravel 5.4 注销重定向
【发布时间】:2018-01-23 07:42:38
【问题描述】:

在 laravel 5.4 中,“auth”中间件的文件位置在哪里,因为我可以在注销后更改默认重定向路径?

在这里,我正在使用 homecontroller.php 中的代码 -

public function __construct()
{
    $this->middleware('auth');
}

现在,我想自定义“auth”中间件。但我找不到位置。

【问题讨论】:

标签: php authentication laravel-5.4 middleware logout


【解决方案1】:

类:app/Http/Controllers/Auth/AuthController.php

将以下属性添加到类中

protected $redirectAfterLogout = 'auth/new_redirect';

【讨论】:

    【解决方案2】:

    我在 供应商\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php

    不建议编辑供应商文件夹中的任何内容,因为如果您将应用程序移动到不同的服务器或将框架升级到新版本。但是,如果您可以接受这种风险,只需将重定向路径更改为您的首选 URL。

     /**
     * Log the user out of the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function logout(Request $request)
    {
        $this->guard()->logout();
        $request->session()->invalidate();
        return redirect('/');
    }
    

    您也可以通过 AuthController 覆盖它(推荐)。只需添加此属性:

    protected $redirectAfterLogout = 'auth/login';
    

    【讨论】:

      猜你喜欢
      • 2018-07-11
      • 2017-09-20
      • 2017-12-27
      • 2018-05-01
      • 2018-12-17
      • 2023-04-08
      • 1970-01-01
      • 2023-03-10
      • 2016-08-23
      相关资源
      最近更新 更多