You're encountering this error because Laravel's default logout route only accepts the DELETE HTTP method, but you're likely triggering it via a GET request (for example, by visiting /logout directly in your browser or using a regular anchor link).
Why does this happen?
- Security: Logging out via GET is discouraged because web crawlers or accidental clicks could log users out unintentionally. That's why Laravel (and most frameworks) require a POST or DELETE request for logout.
- Your Route:
This means only DELETE requests toRoute::delete('/logout', [LoginController::class, 'logout'])->name('logout');/logoutwill work.
Your Blade Code
Your Blade code is correct:
<a href="#" onclick="event.preventDefault();document.getElementById('logoutForm').submit();">
Logout
</a>
<form id="logoutForm" action="{{ route('logout') }}" method="POST" hidden>
@csrf
@method('DELETE')
</form>
This should submit a DELETE request via a hidden form.
Common Issues
-
Visiting
/logoutdirectly:
If you type/logoutin your browser, that's a GET request, which isn't supported. -
JavaScript Disabled:
If JS is disabled, the form won't submit as DELETE. -
Form Submission Not Working:
If the JS isn't firing, the form won't submit.
How to Fix
1. Never use a direct link to /logout
Always use a form with POST + @method('DELETE'), as you did.
2. Make sure your logout link triggers the form submit
Your code is correct, but make sure the JS is working and there are no JS errors on your page.
3. Do NOT add a GET route for logout in production
It's insecure. Stick with POST/DELETE.
4. If you want to use POST instead of DELETE:
Change your route in web.php:
Route::post('/logout', [LoginController::class, 'logout'])->name('logout');
And update your form:
<form id="logoutForm" action="{{ route('logout') }}" method="POST" hidden>
@csrf
<!-- No need for @method('DELETE') if using POST -->
</form>
5. If you want to support both POST and DELETE:
You can do:
Route::match(['post', 'delete'], '/logout', [LoginController::class, 'logout'])->name('logout');
6. If you want to show a 404 for unsupported methods:
Do not add a GET route for /logout. Laravel will automatically return a 405 Method Not Allowed for unsupported methods, which is correct.
Summary
- Do not use a GET route for logout.
- Use a form with POST or DELETE.
- Make sure your logout link triggers the form submission via JS.
- If you want to use POST, update your route and form accordingly.
Example: Recommended Solution
web.php
Route::post('/logout', [LoginController::class, 'logout'])->name('logout');
nav.blade.php
@auth
<li>
<a href="#" onclick="event.preventDefault();document.getElementById('logoutForm').submit();">
Logout
</a>
<form id="logoutForm" action="{{ route('logout') }}" method="POST" hidden>
@csrf
</form>
</li>
@endauth
Never use a GET route for logout in production.
If you follow the above, you will not see the "GET method is not supported" error unless you visit /logout directly, which is not how logout should be triggered.