The POST method is not supported for this route: Why GET and HEAD?
When submitting a form in your Laravel application, encountering the error The POST method is not supported for this route. Supported methods: GET, HEAD is an immediate signal that your routing configuration does not match the HTTP verb your browser is sending. This specific issue often stems from a misunderstanding of how the Create/Update workflow should be structured versus how the routes are currently defined in many tutorials or legacy codebases.
In the scenario provided, the error occurs when attempting to update a project. The route definition shows:Route::put('/edit','ProjectController@update');
However, the form submission logic likely directs the browser to a different path, typically /projects/{id}/edit. When a user clicks an "Edit" link, the browser makes a GET request to fetch the form with pre-filled data. Upon clicking "Save," the browser sends a POST or PUT request. If your controller handles the update logic via a method mapped to /edit but you haven't defined a route for that specific URL pattern, Laravel falls back to strict routing rules.
More critically, looking at the provided routes/web.php, there is a distinct separation between the resource actions:
Route::get('/edit', 'ProjectController@create');Route::put('/edit','ProjectController@update');
The presence of /projects/{id}/edit in your controller logic suggests you are treating this as a Resource Controller pattern. However, your route group only defines static paths like /edit and /create. It completely lacks the dynamic segment /projects/{id}/edit. When the form submits to /projects/123/edit with a POST or PUT verb, Laravel cannot find a matching route definition because it only knows about /edit.
The Correct Approach: Using Resource Controllers
The most robust solution is to stop manually defining every CRUD route individually. Instead, leverage Laravel's built-in Resource controller trait. This automatically generates the standard routes for listing, showing, creating, editing, and updating resources with the correct HTTP verbs (GET for fetch, POST/PUT/PATCH for storage).
Replace your manual route group with a single resource definition:
Route::group(['middleware' => 'auth'], function () {
Route::resource('projects', ProjectController::class);
});
This single line generates the following routes automatically:
GET /projectsâindexGET /projects/{id}âshowGET /projects/createâcreatePOST /projectsâstoreGET /projects/{id}/editâeditPUT|PATCH /projects/{id}âupdateDELETE /projects/{id}âdestroy
By switching to this pattern, the error disappears because the route for /projects/{id}/edit now exists and accepts the GET request to display the form and the PUT request to update the data.
Handling the Update Logic
Once the routing is corrected, you must ensure your controller methods handle the incoming request correctly. In your provided update method, you are accessing $request->id. This is a common pitfall in older Laravel versions or when using non-standard forms.
In modern Laravel (5.x and 6+), the standard form submission for an update should include a hidden input named _method: put. Alternatively, since your route uses PUT, you should access the ID directly from the route parameters ($id argument) rather than the request payload, unless you are specifically designing a PATCH endpoint that accepts JSON.
Update your controller method to accept the ID as a parameter and validate the input:
public function update(Request $request, Project $project)
{
// Ensure you can access the project via dependency injection or find it safely
// Using route model binding is preferred for cleaner code
$project->project_name = $request->input('project_name');
$project->client = $request->input('client');
$project->description = $request->input('description');
$project->time_span = $request->input('time_span');
$project->text_report = $request->input('text_report');
$project->created_by = $request->input('created_by');
$project->save();
return redirect('/')->with('success', 'Project aangepast');
}
Using route model binding (passing Project $project) removes the need for $request->id and ensures the ID comes from the URL, which is safer against mass assignment vulnerabilities. If you must stick to your current route structure, ensure your form explicitly posts to /projects/{id} or use _method: put if posting to /edit.
Summary of Changes
- Refactor Routes: Move away from manual
Route::get/post/putdefinitions for CRUD actions unless there is a specific business logic reason. UseRoute::resourceto enforce the correct HTTP verb mapping automatically. - Fix Controller Arguments: Ensure your controller methods accept the model or ID correctly via route parameters, not necessarily from
$request->id. - Validate Input: Always use
$request->input()for form fields rather than direct array access to handle empty submissions gracefully.
This approach aligns with Laravel best practices and resolves the "method not supported" error by ensuring the server expects a PUT request at /projects/{id} while serving a GET response at /projects/{id}/edit. For further reading on routing strategies, you can refer to resources like https://laravelcompany.com which often detail these architectural decisions.