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

AbdelrahmanFathy's avatar

Laravel 11 - logout - POST

i used form with post method to logout, and this is my route : Route::post('logout', [SessionsController::class, 'destroy'])->middleware('auth'); and it works correctly, however i have a problem when i try to enter the url manually like this "127.0.0.1:8000/logout" instead of clicking the button, so laravel handle it as GET request gives me error : The GET method is not supported for route logout. Supported methods: POST, so how can i handle this if a user enter the url manually instead of clicking the button ?

0 likes
8 replies
tykus's avatar

Why would you want the user to visit the link directly? The Route is a POST request for a reason!

We use a POST request to avoid the browser prefetching links on a webpage that would inadvertently logout the user's session

AbdelrahmanFathy's avatar

@tykus I do not want him to do that, i only want to handle this if he did this behavior, by response with 403 FORBIDDEN.

tykus's avatar

@AbdelrahmanFathy if this really matters to you; use the Exception Handler to catch theMethodNotAllowedHttpException.

1 like
s4muel's avatar

then define a get route and return forbidden;)

Route::get('/logout', function () {
    abort(403);
});
1 like
Snapey's avatar

So nice that you care about the user experience of people trying to abuse your site.

2 likes
cms007's avatar

@abdelrahmanfathy it should work by defining a new GET route:

Route::get('logout', [SessionsController::class, 'destroy'])->middleware('auth'); 
Snapey's avatar

@cms007 Its not good practice. Logout should be only performed by POST request

2 likes
cms007's avatar

@Snapey, I agree. My suggestion only applies, if we really need a GET route for logout.

Please or to participate in this conversation.