Method Not Allowed: Laravel 5.3 + made changes from GET to POST for logout.

The Auth::routes method now registers a POST route for /logout instead of a GET route. This prevents other web applications from logging your users out of your application.

Best way to implement these changes are to do the following:

<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>

Since Auth::routes() already comes with name routes, we are using the route() method for this case. style=”display:none;” can be left out as form usually do not show up if there are no visible input fields.

Categories: Blog

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *