如何使用Laravel 5.4注销并重定向到登录页面? [英] How to logout and redirect to login page using Laravel 5.4?

查看:103
本文介绍了如何使用Laravel 5.4注销并重定向到登录页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5.4并尝试实现身份验证系统.我使用php artisan命令make:auth对其进行设置.我根据布局编辑了视图.现在,当我尝试注销时,抛出此错误

I am using Laravel 5.4 and trying to implement authentication system. I used php artisan command make:auth to setup it. I edited the views according to my layout. Now, when I am trying to logout it throwing me this error

NotFoundHttpException:

NotFoundHttpException in RouteCollection.php line 161:

有人可以帮助我如何注销吗?

could any one help me how to logout?

推荐答案

在您的web.php(路线)中:

添加:

Route::get('logout', '\App\Http\Controllers\Auth\LoginController@logout');

在您的LoginController.php

添加:

public function logout(Request $request) {
  Auth::logout();
  return redirect('/login');
}

此外,在namespace

添加:

use Auth;

现在,您可以使用yourdomain.com/logout URL登出,或者如果您已创建logout button,则将href添加到/logout

Now, you are able to logout using yourdomain.com/logout URL or if you have created logout button, add href to /logout

这篇关于如何使用Laravel 5.4注销并重定向到登录页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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