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
149
Related Errors
PHP
Maximum Execution Time Exceeded
A script ran longer than the allowed maximum execution time limit.
Database
Unknown Column
The SQL query references a column that doesn't exist in the specified table.
Laravel
MalformedPayloadException
The request payload or session data is corrupted or invalid.
PHP
Cannot Use String Offset as Array
The code tries to access a string using array syntax, treating it as an array.