The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel
There are multiple ways you can handle this:
If you insist on using
PUT
you can change the form action toPOST
and add a hiddenmethod_field
that has a valuePUT
and a hidden csrf field (if you are using blade then you just need to add@csrf_field
and{{ method_field('PUT') }}
). This way the form would accept the request.You can simply change the route and form method to
POST
. It will work just fine since you are the one defining the route and not using the resource group.
I know this is not the solution to OPs post. However, this post is the first one indexed by Google when I searched for answers to this error. For this reason I feel this will benefit others.
The following error...
The POST method is not supported for this route. Supported methods: GET, HEAD.
was caused by not clearing the routing cache
php artisan route:cache
I've seen your code in web.php as follows: Route::post('/edit/{id}','ProjectController@update');
Step 1: remove the {id} random parameter so it would be like this: Route::post('/edit','ProjectController@update');
Step 2: Then remove the @method('PUT') in your form, so let's say we'll just plainly use the POST method
Then how can I pass the ID to my method?
Step 1: make an input field in your form with the hidden attribute for example
<input type="hidden" value="{{$project->id}}" name="id">
Step 2: in your update method in your controller, fetch that ID for example:
$id = $request->input('id');
then you may not use it to find which project to edit
$project = Project::find($id)
//OR
$project = Project::where('id',$id);