php - 我的 laravel 应用程序没有选择正确的路线
问题描述
我的 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>
笔记本电脑控制器
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
推荐阅读
- database - 仅使用一个节点(服务器)时,elasticSearch 是否仍然有用?
- powershell - Start-Process 在 ArgumentList 中传递哈希表
- vba - VBA中基于调整单元格的公式
- spring - 我如何 RequestMapping 正则表达式禁用任何单词?
- java - 重新打包 Spring Boot 应用程序
- c - C中文字的生命周期
- python - 如何在linux服务器的python3中使用python2模块?
- java - 使用递归地图(Map of Maps)是一种好习惯吗
- python - 在多个标题数据框中选择一列
- groovy - groovy.lang.MissingPropertyException:没有这样的属性:类的getBtnRCR:CustomerCommonRequestBean