MethodNotAllowedHttpException (405)
The HTTP method used is not allowed for the requested route.
Explanation
MethodNotAllowedHttpException is thrown when you send a request using an HTTP method (GET, POST, PUT, DELETE, etc.) that is not defined for the given route. For example, submitting a form as GET when the route only accepts POST will trigger this error. This commonly happens with HTML forms that default to GET, or when API clients send requests with the wrong method. Laravel returns a 405 status code and lists the allowed methods in the Allow header.
Common Causes
- HTML form defaulting to GET instead of POST
- AJAX request using wrong HTTP method
- Route defined with wrong method
- Missing @method directive in Blade form
- API client sending incorrect method
Solution
Check your route definitions in routes/web.php or routes/api.php to confirm which HTTP methods are allowed. Verify that your HTML form has the correct method attribute or that your AJAX request uses the right method. Use the Route::resource() helper which automatically registers routes for all standard CRUD methods. If you need to support multiple methods, use Route::match() or Route::any(). Ensure you have the @csrf and @method directives in Blade forms for PUT/PATCH/DELETE.
Code Example
// Route only accepts GET
Route::get('/users', [UserController::class, 'index']);
// Form submits as POST - this causes 405
<form method="POST" action="/users">
@csrf
...
</form>
// Fix: Match the form method to the route
Route::post('/users', [UserController::class, 'store']);
// Or use resource routes for full CRUD
Route::resource('users', UserController::class);
// In Blade forms, use @method for PUT/PATCH
@method('PUT')
Error Information
Language
php
Framework
laravel
Difficulty
Beginner
Views
148
Related Errors
503
DevOps
Service Unavailable (503)
The server is temporarily unable to handle requests due to overload or maintenance.
PHP
Fatal Error: Uncaught Error
An unhandled Error exception was thrown that crashed the script.
429
Backend
Rate Limit Exceeded (429)
Too many requests were sent in a given amount of time.
Database
Column Count Doesn't Match
The number of values in an INSERT statement doesn't match the number of columns.