I have a form when I update user data. When I press button update show me error The PUT method is not supported for route customers/5/edit. Supported methods: GET, HEAD.
. I check my code but I can’t find error.
route
Route::post('store', 'AppHttpControllersCustomerController@store')->name('customers.store');
Route::get('/{customer}/edit', 'AppHttpControllersCustomerController@edit')->name('customers.edit');
Route::put('/{customer}', 'AppHttpControllersCustomerController@update')->name('customers.update');
controller
public function edit(Customer $customer)
{
return view('edit', compact('customer'));
}
public function update(Customer $request, $id)
{
$customers = Customer::find($id);
$customers->first_name = $request->input('first_name');
$customers->last_name = $request->input('last_name');
$customers->update();
return redirect('/');
}
view
<form action="{{ route('customers.store') }}" method="post">
<div class="form-outline mb-4">
<input type="text" id="form4Example1" class="form-control" value="{{ $customer->first_name }}"/>
<label class="form-label" for="form4Example1">First name</label>
</div>
<div class="form-outline mb-4">
<input type="text" id="form4Example1" class="form-control" value="{{ $customer->last_name }}"/>
<label class="form-label" for="form4Example1">Last name</label>
</div>
</form>
2
Answers
Because your put end-point is called
customers.update
notcustomers.store
.Your form action should be:
Also take a look at Method Spoofing.
On a side note, you would be better off using Resource Controllers to better enforce the CRUD standard.
You can use Partials to trim down the full CRUD spec of a resource.
Route method:
Blade Logic
Controller Logic: