Laravel 6-缺少[路由:供应商。销毁] [URI:供应商/ {供应商}]所需的参数

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

我的索引页带有一个按钮,用于从表中删除列。

@foreach ($suppliers as $supplier)
        <tr>
              <th>{{ $supplier -> idSupplier }}</th>
              <th style="color:blue;"><a href="/suppliers/{{$supplier->idSupplier}}">{{ $supplier -> column1 }}</a></th>
              <th>{{ $supplier -> column2 }}</th>
              <th>{{ $supplier -> column3  }}</th>
              <th>{!! $supplier -> column4 !!}</th>
              <th>
                  <a class="btn btn-warning" href="/suppliers/{{$supplier->idSupplier}}/edit" role="button">
                        <i class="fa fa-tools"></i>
                  Edit</a>
                  <a class="btn btn-danger" href="{{ action('SuppliersController@destroy') }}" role="button">
                        <i class="fa fa-eraser"></i>
                  Delete</a>
              </th>
        </tr>
@endforeach

但是现在每次打开索引页面时,都会显示此错误消息

Facade \ Ignition \ Exceptions \ ViewException缺少必需的参数用于[路线:Suppliers.destroy] [URI:供应商/ {供应商}]。 (视图:C:\ xampp \ htdocs \ Invent \ resources \ views \ suppliers \ index.blade.php)

这是我的路线

Route::resource('suppliers', 'SuppliersController');

这是destroy中的SuppliersController函数>

public function destroy($idSupplier)
    {
        $supplier = Supplier::find($idSupplier);
        $supplier->delete();
        return redirect('/suppliers')->with('success', 'Supplier removed');
    }

我已经尝试过this solution,它给了我另一个错误消息。

i具有带有按钮的索引页,该按钮用于从表中删除列。 @foreach($ supplier as $ supplier)

{{$ supplier-> idSupplier}} ...]
php laravel laravel-6
3个回答
0
投票

我建议使用确认模式进行一些改进。然后,我将表单提交给控制器。


0
投票

您正在调用不带参数的de destroy方法,您可以像这样进行操作


0
投票

嗯,您没有传递控制器操作所需的参数。 destroy方法接收参数idSupplier以执行其操作。从刀片服务器上,您只是在不传递参数的情况下调用控制器操作。使其如下所示:

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