Laravel answers a form or AJAX POST with 405 Method Not Allowed
405 Method Not AllowedShort answer
A 405 in Laravel means the URL exists but not for the HTTP verb you sent. Run php artisan route:list and compare the verb with the request. Usual causes: the route is declared with get(), an HTML form sends PUT or DELETE without a _method field, or a cached route file is out of date.
Fix it fast
1Find out which cause you have
List the routes for the URL and read the Method column. If POST is not in it for that URI, the request never had a chance.
php artisan route:list --path=orders2Match what you see, then jump to its fix
- 1
route:list shows GET|HEAD for the URI, and POST is missingThe route is registered for a different verbFix - 2
The route is Route::put(), Route::patch() or Route::delete(), and the failing call comes from a <form>An HTML form sends PUT, PATCH or DELETE without the _method fieldFix - 3
The route exists in routes/web.php, but route:list does not show it and nothing changed after you saved the fileThe route cache was built before the route was addedFix
- 1
What does the error look like?
405 Method Not AllowedA POST, PUT or DELETE call returns status 405 while the same URL opens fine with GET
Cause 1 of 3
The route is registered for a different verb
1Check
Compare the verb in route:list with the method of your form or fetch call.
grep -n "orders" routes/web.php routes/api.php2Fix
Declare the route with the verb you send. Use Route::match or Route::any only when one URI really has to accept several.
Route::post('/orders', [OrderController::class, 'store']);
// one URI, two verbs
Route::match(['get', 'post'], '/orders', [OrderController::class, 'handle']);3Verify
route:list now shows POST, and the request returns the controller's response.
php artisan route:list --path=ordersConfirmed by laravel.com
Cause 2 of 3
An HTML form sends PUT, PATCH or DELETE without the _method field
1Check
HTML forms can only send GET or POST, so the browser posts to a PUT route and gets 405.
grep -n "<form" resources/views/orders/edit.blade.php2Fix
Keep method="POST" on the form and add the _method field. Blade has a directive for it, and the form also needs the CSRF field.
<form action="/orders/{{ $order->id }}" method="POST">
@csrf
@method('PUT')
...
</form>3Verify
Submit the form again: the PUT route should run.
php artisan route:list --path=ordersConfirmed by laravel.com
Cause 3 of 3
The route cache was built before the route was added
1Check
With a cached route file, new routes are ignored until the cache is rebuilt. Laravel's docs say to rebuild it when you add routes.
ls bootstrap/cache2Fix
Clear the cache while developing, or run route:cache again as part of every deploy.
php artisan route:clear
# production, after deploy:
php artisan route:cache3Verify
The new route shows up in route:list.
php artisan route:list --path=ordersConfirmed by laravel.com
How do I stop it coming back?
- Run php artisan route:list after adding any route, and keep that habit in code review.
- Put route:cache in the deploy script so the cache can never lag behind the code.
- Use Blade's @method and @csrf in every form that is not a plain GET.
- For AJAX calls, send the exact verb the route declares.
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
Back 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 fixBack end
Composer says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fix