【问题标题】:laravel logout function doesnt worklaravel注销功能不起作用
【发布时间】: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'); },只要标记一下,注销功能就可以了

标签: php laravel logout


【解决方案1】:

如果你使用 php artisan make:Auth 你可以简单地使用这个代码来制作注销链接

<a href="{{url('/logout')}}">Logout </a> 

或者你可以在默认布局中使用 laravel 注销按钮

<a class="dropdown-item" href="{{ route('logout') }}"
   onclick="event.preventDefault();
                 document.getElementById('logout-form').submit();">
    Logout
</a>

<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
    @csrf
</form>

【讨论】:

  • 是的,我做到了,好的,我会改进它,非常感谢您的建议
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-25
  • 2018-03-12
  • 1970-01-01
  • 2017-01-07
  • 2013-02-15
  • 1970-01-01
  • 2017-01-26
相关资源
最近更新 更多