Answer the question
In order to leave comments, you need to log in
What is the path to write in the update route to get to the page with the update form?
Routes
Route::get('/edit/{id}', '[email protected]')->name('adEdit');
Route::get('/edit/{id}', '[email protected]')->name('adUpdate');
<form method="post" class="col-md-6" action="{{ route(‘update’, $oneAd->id) }}">
<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">Save</button>
@csrf
</form>
public function edit($id)
{
$ad = Ad::find($id);
return view('update', [
'ad' => $ad
]);
}
public function update(Request $request, $id)
{
$oneAd = Ad::find($id);
$id = $oneAd->update([
'title' => $request->title,
'description' => $request->description,
'user_id' => Auth::user()->id,
'author_name' => Auth::user()->username
])->id;
return redirect("/");
}
<a href="/edit/{{ $oneAd->id }}" class="btn btn-primary">Update</a>
Answer the question
In order to leave comments, you need to log in
You have both routes have the same path, so the last one works (he overwrote the first one).
To solve the problem, first attribute the following uri - /edit/{id}/update
And everything will work
Another option is to change the method for update
And in the form, insert
This method, as for me, is the most correct, as it meets the logic @method('PATCH')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question