【发布时间】:2018-03-29 00:30:35
【问题描述】:
我已经成功创建了登录功能,但是注销功能不起作用!!! 这是我的代码
在刀片中注销 =>
<a href="{{ action('Auth\LoginController@getLogout')}}"> logout</a>
在 Auth\LoginController.php 中注销=>
public function getLogout(){
return redirect('login')->with(Auth::logout());
}
当我按下退出按钮时,浏览器将自动返回主页。
在我的代码中,它应该返回登录页面,并且它也没有成功注销。
因此,这个函数 getLogout() 它不起作用!!!
有人知道吗?为什么它总是把页面翻到首页?
【问题讨论】:
-
您希望
->with(Auth::logout());做什么?->with(..)用于将变量传递给视图。只需将Auth::logout()放在 return 语句之前。 -
查看通过 auth 命令创建的示例页面,您需要链接后的小表单才能访问已登录的用户令牌。
-
我在这种情况下找到了原因。在Auth\LoginController.php中有一段代码,这段代码会将页面转到中间件
public function __construct() { $this->middleware('guest')->except('logout'); },只要标记一下,注销功能就可以了