Summer Sale! All accounts are 50% off this week.

cola's avatar
Level 1

Why: The GET method is not supported for this route. Supported methods: POST.

    public function dologout() {
        Auth::logout();
        return redirect('/showlogin');
    }

Route::post('/dologout', [UserController::class, 'dologout']);

Why do I get this error: The GET method is not supported for this route. Supported methods: POST. ?

0 likes
5 replies
laracoft's avatar

@cola

Because you are using Route::post(...). Change it to Route::get(...)

But it is not good practice to use GET for logging out.

cola's avatar
Level 1

How can I logout using Route::post(...)? What is the good practice to logging out?

laracoft's avatar

Good practice is to use POST.

In your HTML

<form action="/dologout" method="post">
    <input type="submit" value="Submit">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
martinbean's avatar

@cola Why are you even creating a logout route in the first place when Laravel has two options for authentication out of the box…?

Snapey's avatar

Why do I get this error: The GET method is not supported for this route. Supported methods: POST. ?

No idea because you don't show HOW you try and access this route?

Please or to participate in this conversation.