Reputation: 310
while passing variable in URL to edit and update a form it's returning only 404 not found , the tutorials did not help me , so this is my code :
controller : rendezv.php
public function editer ($id) {
$rdv= rendezvous::findOrFail('id');
return view ('/edit', ['modifier'=>$rdv]);
}
public function update(Request $request ,$id)
{
$this->validate($request, [
'email' => 'required' ,
'tel' => 'required'
]);
//modifier rendez vous
$editer=rendezvous::findOrFail('id');
$editer->Email = $request->input('email');
$editer->tel = $request->input('tel');
$editer-> save();
return redirect('/index');
}
and this this edit.blade.php
<form action="/update/{{$modifier->id}}" method="post" role="form" data-aos="fade-up">
@csrf
<input type="hidden" name="_method" value="PATCH" />
<input placeholder="{{$modifier->Email}}" type="email" class="form-control" name="email" id="email" data-msg="Please enter your name " />
<input placeholder="{{$modifier->Numéro_de_téléphone}} " type="text" class="form-control" name="tel" id="subject" data-rule="minlen:8" data-msg="Please enter at least 8 numbers" /> </i>
<div id="buttons">
<button type="submit" class="btn btn-primary"> modifier </button>
</div>
</form>
and finally route :
Route::get('/rendezvous_{ID}', 'doctor@rdv');
Route::post('/rdv','rendezv@rdv');
Route::post('/bienvenu','doctor@authentification')->name('aziz');
Route::get('/edit/{id}','rendezv@editer');
need yr help guys , and thank you
Upvotes: 0
Views: 4751
Reputation: 11
You are missing a post route:
Route::post('/edit/{id}','rendezv@update');
Upvotes: 1
Reputation: 521
Please add the route for update
Route::patch('/update/{id}','rendezv@update');
You get 404
for both edit and update for findOrFail()
method. You are passing string
'id'
instead of $id
.
In editer
method please replace
$rdv= rendezvous::findOrFail('id');
with
$rdv= rendezvous::findOrFail($id);
In update
method please replace
$editer=rendezvous::findOrFail('id');
With
$editer=rendezvous::findOrFail($id);
Furthermore, findOrFail()
method will return 404
if no data is found with the given $id
Upvotes: 2
Reputation: 8927
Take a look at the Resource Controllers
What you are looking for is a Route::post('/edit/{id}','rendezv@update');
or put
or patch
Upvotes: 1
Reputation: 2951
You route /update/{{$modifier->id}}
doesn't exist, you need to declare it in you router file:
Route::post('/update/{id}','rendezv@update');
Upvotes: 1