The GET method is not supported for route logout. Supported methods: POST in laravel when manually type logout in url

126 Views Asked by At

My laravel version is 9.19. When I click on logout menu its working fine. But when I manually type 'logout' in url it gives the error - The GET method is not supported for route logout. Supported methods: POST.

enter image description here

It shows as a POST route in route:list:

POST logout .............. logout › Auth\LoginController@logout

in web.php:

Auth::routes( [ 'register' => false ] );

How can i solve this in case of manually type 'logout' in url?

1

There are 1 best solutions below

0
Md. Shamvil Hossain On

Found a solution, added this into my web.php

Route::get('/logout', function () {
    Auth::logout();
    return redirect()->route('login');
})->name('logout');