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
31
Related Errors
PHP
Call to a Member Function on Null
The code calls a method on a variable that is null instead of an object.
PHP
Parse Error: Syntax Error
PHP detected a syntax error in the source code that prevents parsing.
Database
Lock Wait Timeout Exceeded
A database query waited too long for a lock held by another transaction.
Database
Table Doesn't Exist
The SQL query references a table that doesn't exist in the database.