Answer the question
In order to leave comments, you need to log in
How to correctly implement the update method for the declaration?
Controller
public function edit($id)
{
$ad = Ad::find($id);
return view('update', [
'ad' => $ad
]);
}
public function update(Request $request, $id)
{
$ad = Ad::find($id);
$data = $request->all();
$result = $ad->fill($data)->save();
return redirect('/');
}
Route::get('/edit/{id}', '[email protected]')->name('adUpdate');
<form method="post" class="col-md-6" action="{{ route(''adUpdate) }}">
@method('PATCH')
<div class="form-group">
<label>Title</label>
<input type="text" name="title" class="form-control">
@error ('title')
<small class="form-text text-danger">{{ $message }}</small>
@enderror
</div>
<div class="form-group">
<label>Description</label>
<textarea type="text" name="description" class="form-control"></textarea>
@error ('description')
<small class="form-text text-danger">{{ $message }}</small>
@enderror
</div>
<button type="submit" class="btn btn-primary">Create</button>
@csrf
</form>
Answer the question
In order to leave comments, you need to log in
You have the routa method written incorrectly in the form, it should be sent using the PATH method
And you have an appeal to get
PS And still at you action of the form is not correctly written. Take a closer look at how the quotes are in route () and you do not pass the required $id parameter
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question