我的laravel应用程序未选择正确的路线

问题描述 投票:0回答:1

我的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]);
    }
php laravel laravel-5.8
1个回答
0
投票

这是不正确的,它仅输出ID:

<form method="post" action="{{$laptop->id}}">

您需要指定路线:

<form method="post" action="{{ route('name-of-route', $laptop-id) }}">

您可以使用php artisan route:list获取路线的名称

© www.soinside.com 2019 - 2024. All rights reserved.