My laravel application should move to route “mango/public/4” but it moves to “mango/public/4/4”. Route file
JavaScript
x
route::get('/{id}/edit','LaptopController@edit');
route::patch('/{id}','LaptopController@update');
Update(view)
JavaScript
<form method="post" action="{{$laptop->id}}">
@csrf
@method('PATCH')
<table width="100%">
<tr>
<td>Enter Name</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Enter Description</td>
<td><input type="text" name="description"></td>
</tr>
<tr>
<td><button>Update</button></td>
</tr>
</table>
</form>
LaptopController
JavaScript
public function edit($id){
$laptop=Laptop::find($id);
return view('update',['laptop'=>$laptop]);
}
Advertisement
Answer
You can do it easy if you name your route
When your action is just an id for example action="4"
, it means that form will be sent to relative path, and that’s why you have /4/4
in your url
JavaScript
// web.php
route::patch('/{id}','LaptopController@update')->name('laptop.update');
// update view
<form method="post" action="{{ route('laptop.update', ['id' => $laptop->id]) }}">