我已经成功创建登录功能,但注销功能不起作用! 这是我的代码
在blade中退出=>
<a href="{{ action('Auth\LoginController@getLogout')}}"> logout</a>
注销Auth \ LoginController.php =&gt;
public function getLogout(){
return redirect('login')->with(Auth::logout());
}
当我按下退出按钮时,浏览器将自动返回主页。
在我的代码中,它应该返回到登录页面,它也不会成功注销。
因此,这个函数getLogout()它不起作用!!!!
有人知道吗?为什么它总是将页面转到主页?
答案 0 :(得分:0)
如果您使用php artisan make:Auth您只需使用此代码进行注销链接
<a href="{{url('/logout')}}">Logout </a>
或者你可以在默认布局中使用laravel logout按钮
<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>