我的 laravel 应用程序没有选择正确的路线
My laravel application is not picking right route
我的 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
获取路线名称
如果你给你的路线命名,你就可以轻松完成
当你的操作只是一个 id 例如 action="4"
,这意味着表单将被发送到相对路径,这就是为什么你的 url
中有 /4/4
// web.php
...
route::patch('/{id}','LaptopController@update')->name('laptop.update');
// update view
<form method="post" action="{{ route('laptop.update', ['id' => $laptop->id]) }}">
我的 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
如果你给你的路线命名,你就可以轻松完成
当你的操作只是一个 id 例如 action="4"
,这意味着表单将被发送到相对路径,这就是为什么你的 url
/4/4
// web.php
...
route::patch('/{id}','LaptopController@update')->name('laptop.update');
// update view
<form method="post" action="{{ route('laptop.update', ['id' => $laptop->id]) }}">