【发布时间】:2018-07-03 05:16:34
【问题描述】:
当我尝试去http://mysite/logout时,我得到了
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
没有消息
路线:
Auth::routes();
php artisan route:list的一部分
+-----------+-------------------------+---------------------+------------------------------------------------------------------------+--------------+
| Method | URI | Name | Action | Middleware |
+-----------+-------------------------+---------------------+------------------------------------------------------------------------+--------------+
| POST | logout | logout | App\Http\Controllers\Auth\LoginController@logout | web |
当我使用这个默认按钮时
<a 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_field() }}
</form>
一切正常。
编辑:添加了我自己的答案。
【问题讨论】:
-
你需要发出post请求,这里你正在发出get请求
-
@Sohel0415 我可以禁止某些路线的 GET 吗?
-
是的,你在路由文件中指定了这个
标签: php laravel-5.5