0

我创建了如下所示的路线

Route::resource('reports/', 'ReportController')->middleware('auth');

在路线列表中,我有如下列表

DELETE    | reports/{}             | destroy          | App\Http\Controllers\ReportController@destroy  

在 index.blade.php 我创建了一个删除按钮,如下所示

<form method="post" action="{{route('destroy',['report'=>$report->id])}}" onsubmit="return confirm('Are you sute to delete?')">
             @csrf 
             @method("delete")
             <button type="submit" class="btn btn-danger btn-sm">Delete</button>
 </form>

ReportController 销毁方法:

public function destroy(Report $report)
{
     //
}

但我得到以下错误

Missing required parameters for [Route: destroy] [URI: reports/{}].
4

2 回答 2

0

您的路线应如下所示:

DELETE    | reports/{report}             | destroy          | App\Http\Controllers\ReportController@destroy 

并且模型 Report 必须像这样添加到 RouteServiceProvider.php 中:

public function boot()
{
    parent::boot();

    Route::model('report', App\Report::class);

这是路由模型绑定。在这里阅读https://laravel.com/docs/7.x/routing#explicit-binding

于 2020-06-16T15:38:18.800 回答
0

从您的路线中删除 /

Route::resource('reports/', 'ReportController')->middleware('auth');

Route::resource('reports', 'ReportController')->middleware('auth');

检查文档

于 2020-06-16T16:12:39.430 回答