form method="put" action="{{URL::action('siteController@update')}}" accept-charset="UTF-8"></form>
Route::post('site/update/{id}', 'siteController@update');
public function update(Request $request, $id)
{
//
$this->validate($request,[
'Name' => 'required',
'Description' => 'required',
'Status' => 'required'
]);
$Data = site::find($id);
$Data->Name = $request->Name;
$Data->Description = $request->Description;
$Data->Status = $request->Status;
if($Data->save())
{
return $this->index();
}else{
return redirect()->back()->withErrors($errors,$this->errorBag());
}
}
By adding a name to your route such as
Route::post('site/update/{id}', 'siteController@update')->name('site-update');
It allows you to generate its URL without knowing it at all
<form method="post" action="{{ route('site-update', compact('id')) }}">
@csrf
add your form field here and use button type submit
</form>
Even if you decide to change the URL, the route
helper does not care as long as the name stays the same (it's just an alias)
Try This,
<form method="post" action="{{ url('site/update/', ['id' => $id]) }}">
@csrf
add your form field here and use button type submit
</form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.