------Platform Laravel 7x. --------
I am stuck in a simple problem. I can't find the error. While I am updating a form, it redirects to a wrong URL which I don't want and data doesn't update.
Form action url:
method="POST" action="{{'city/update/'. $editCity->id}}"
Route:
Route::post('city/update/{id}','Admin\CityController@update');
Function from controller:
public function update(Request $request, $id)
{
$editCity=City::find($id);
$editCity->city_name=$request->city_name;
$editCity->save();
return redirect()->back();
}
When I click on update it goes to this URL and shows 404 error which I don't want:
public/panel/city/edit/city/update/33
Help me to find out the problem where is the mistake I have done. I want to make it updated when I click on the update button and return back.
Use name route instead. So your code will look like :
blade.php
method="POST" action="{{ route('city.update', $editCity->id) }}"
web.php
Route::post('city/update/{id}','Admin\CityController@update')->name('city.update');