Everything in this login is working fine but if a user tries logout route directly
localhost:8000/logout it shows the following error
i want a way so that i can redirect to login if the route is called directly, what could be the vest way for it.
Everything in this login is working fine but if a user tries logout route directly
localhost:8000/logout it shows the following error
i want a way so that i can redirect to login if the route is called directly, what could be the vest way for it.
A word of caution: As Laurel mentioned in this comments, using
GET
request forLogout
is a bad idea, Read this discussion on StackOverflow before proceeding.
Where is the problem?
The
logout
route doesn't support HTTP MethodGET
, butPOST
.
What is the solution?
You can define a GET
route for logout
, if you really wants to do it.
Route::get('logout', function() {
// Do whatever you want to do with Logout
Auth::logout(); // logout the user
return redirect()->route('login'); // redirect the user to login page
});
define a route like this in your routes file. It is because only post method exist for logout.