我的laravel应用程序应移至路由“ mango / public / 4”,但移至“ mango / public / 4/4”。路由文件
route::get('/{id}/edit','LaptopController@edit');
route::patch('/{id}','LaptopController@update');
更新(视图)
<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
public function edit($id){
$laptop=Laptop::find($id);
return view('update',['laptop'=>$laptop]);
}
这是不正确的,它仅输出ID:
<form method="post" action="{{$laptop->id}}">
您需要指定路线:
<form method="post" action="{{ route('name-of-route', $laptop-id) }}">
您可以使用php artisan route:list
获取路线的名称