Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Robinvm's avatar

Route to logout

Hello, does anyone have the route for in the web.php to logout, i think i deleted it :(

0 likes
11 replies
JoshMountain's avatar

Hi @Robinvm,

This post may help you out: http://stackoverflow.com/a/39197278/1538275

If you are using the authentication scaffolding provided by Laravel you can simply add Auth::routes(); anywhere in your web.php file and all your authentication routes will be included automatically. To answer your question more specifically, the logout route would look something like this in web.php:

Route::post('logout', ['as' => 'logout', 'uses' => 'Auth\LoginController@logout'])

Robinvm's avatar

@user10 im using that auth::routes, how can i logout a user with a button then?

Robinvm's avatar

@JoshMountain i got this but it doesnt work </a href="{{ url('/logout') }}" > without that / at the end

SaeedPrez's avatar

Laravel is actually sending POST request to logout these days.. so just linking to '/logout' won't work unless you change the route to Route::get() instead of Route::post()

                                <ul class="dropdown-menu" role="menu">
                                    <li>
                                        <a href="{{ url('/logout') }}"
                                            onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();">
                                            Logout
                                        </a>

                                        <form id="logout-form" action="{{ url('/logout') }}" method="POST" style="display: none;">
                                            {{ csrf_field() }}
                                        </form>
                                    </li>
                                </ul>

PS. You can always run php artisan make:auth to generate the files again, just make sure you backup the old ones if you have made any changes in them.

6 likes
cent040's avatar
Route::get('/logout', 'Auth\LoginController@logout');
8 likes

Please or to participate in this conversation.