如何设置laravel 5.3注销重定向路径? [英] How to set laravel 5.3 logout redirect path?

查看:61
本文介绍了如何设置laravel 5.3注销重定向路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Laravel 5.3中注销后,是否没有精美的解决方案来重定向到特定页面?

Is there no elegant solution to redirect to a specific page after logging out in Laravel 5.3?

正在调用的功能来自特征 AuthenticatesUsers :

The function being called is from the trait AuthenticatesUsers:

public function logout(Request $request)
{
    $this->guard()->logout();

    $request->session()->flush();

    $request->session()->regenerate();

    return redirect('/');
}

这是laravel核心的默认功能.因此,我必须重写无法编辑核心的全部功能. 但是还没有一个更简单的解决方案,导致手动注销,刷新并重新生成文件感觉有点过头了.

This is a default function from the core of laravel. So I have to override the whole function I cannot edit the core. But isn't there a more simpler solution, cause it feel like overkill to manually logout, flush and regenerate again.

解决了一篇文章中的答案: https://codeneverlied. com/how-to-to-set-logout-redirect-path-in-laravel-5-8-and-before/

Worked the answers out in an article: https://codeneverlied.com/how-to-set-logout-redirect-path-in-laravel-5-8-and-before/

推荐答案

这就是我的方法.在Auth \ LoginController中,您可以:

This is how I did it. In Auth\LoginController you have:

use AuthenticatesUsers;

将其更改为:

use AuthenticatesUsers {
    logout as performLogout;
}

然后,在LoginController中定义一个新的logout()方法:

Then, define a new logout() method in your LoginController:

public function logout(Request $request)
{
    $this->performLogout($request);
    return redirect()->route('your_route');
}

当然,该特征中的常规logout()方法只有3行(用于将用户注销到系统中),因此您可以将它们复制到您的方法中,但是您应始终遵循DRY原则(不要重复自己)并尽可能多地重复使用代码.

Sure, regular logout() method in that trait has only 3 lines (used to log users out of the system) so you can copy them to your method, but you should always follow the DRY principle (don't repeat yourself) and re-use as much code as you can.

这篇关于如何设置laravel 5.3注销重定向路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆