首页 > 解决方案 > 我的 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]);
    }

标签: phplaravellaravel-5.8

解决方案


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

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

您需要指定路线:

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

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


推荐阅读