Laravel returns 405 Method Not Allowed for a form or API call
405 Method Not AllowedShort answer
A 405 means the URL exists but not for the HTTP verb you sent. In Laravel that is a verb mismatch between the request and the route: a form sending POST to a PUT route, a call using GET on a POST route, or a catch-all route declared before the specific one. Run route:list, compare the verb, then fix the form or the route.
Fix it fast
1Find out which cause you have
List the routes for the URL and read the Method column. The verb of your request must be one of them. The Allow header of the 405 response lists them too.
php artisan route:list --path=login2Match what you see, then jump to its fix
- 1
The route list shows PUT|PATCH or DELETE for the URL and the form uses method="POST".A form sends POST but the route is PUT, PATCH or DELETEFix - 2
The request verb is not one of the verbs route:list shows for that URI.The request uses a verb the route was not declared withFix - 3
route:list shows two routes for the same URI, and the specific one is below the catch-all.A route with any, match or redirect shares the URI and comes firstFix
- 1
What does the error look like?
405 Method Not AllowedHTTP/1.1 405 Method Not Allowed
Cause 1 of 3
A form sends POST but the route is PUT, PATCH or DELETE
1Check
HTML forms only support GET and POST, so another verb must be sent as a hidden _method field.
grep -rn "<form" resources/views | head2Fix
Keep method POST on the form and add the @method directive, together with @csrf.
<form action="/posts/1" method="POST">
@method('PUT')
@csrf
</form>3Verify
Submit the form again; the route now matches.
php artisan route:list --path=postsConfirmed by raw.githubusercontent.com
Cause 2 of 3
The request uses a verb the route was not declared with
1Check
Typing a POST-only URL in the address bar sends GET. A fetch call may also use the wrong method.
php artisan route:list -v --path=api2Fix
Send the verb the route supports, or declare the route for the verb you need. Route::match covers a list of verbs, Route::any covers all.
Route::match(['get', 'post'], '/contact', [ContactController::class, 'handle']);3Verify
Repeat the request with the intended verb and read the status line.
curl -i -X POST https://example.com/contactConfirmed by raw.githubusercontent.com
Cause 3 of 3
A route with any, match or redirect shares the URI and comes first
1Check
Laravel's docs say routes using get, post, put, patch, delete or options must be defined before any, match or redirect routes with the same URI.
php artisan route:list --path=orders2Fix
Move the specific verb routes above the broad one in routes/web.php or routes/api.php.
Route::post('/orders', [OrderController::class, 'store']);
Route::any('/orders', fn () => abort(404));3Verify
Run route:list again and call the URL with the intended verb.
php artisan route:list --path=ordersConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Read the Method column of route:list whenever a new endpoint is added.
- Always pair @method with @csrf in forms that are not plain GET or POST.
- Declare specific verb routes before any, match or redirect routes.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Security
Laravel answers a form or AJAX call with 419 Page Expired
419 Page Expired (a POST, PUT, PATCH or DELETE request)
Laravel could not match the CSRF token in your request to the one stored in the visitor's session.
5 causes, each with a fixBack end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fix