我正在使用Laravel Yajra dataTable 如何解决此错误?
Missing required parameters for [Route: plane.destroy] [URI: plane/{plane}/id].
我的控制器:
if ($request->ajax()) {
$plane = Plane::with('presidents', 'years', 'plantypes')->selectRaw('distinct planes.*')->get();
return DataTables::of($plane)
->addColumn('p_name', function (Plane $plane) { // change this code based on your need
return $plane->presidents->map(function ($president) {
return str_limit($president->P_name);
})->implode('<br>');
})
->addColumn('action', function ($plane) {
$btn = '<a href="javascript:void(0)" data-toggle="tooltip" data-id="' . $plane->id . '" data-original-title="Edit" class="edit btn btn-primary btn-sm editItem">Edit</a>';
$btn = $btn . ' <a href="javascript:void(0)" data-toggle="tooltip" data-id="' . $plane->id . '" data-original-title="Delete" class="btn btn-danger btn-sm deleteItem">Delete</a>';
return $btn;
})
->rawColumns(['p_name', 'action'])
->make(true);
}
return $dataTable->render('planes.index');
js代码:
$('body').on('click', '.deleteItem', function () {
var id = $(this).data("id");
confirm("Are You sure want to delete !");
$.ajax({
type: "DELETE",
url: "{{ route('plane.destroy') }}"+'/'+id,
success: function (data) {
table.draw();
},
error: function (data) {
console.log('Error:', data);
}
});
});
我的路线:
Route :: resource('plane','PlaneController');
答案 0 :(得分:1)
传递网址,而不是route
。您在资源中调用的模型将为plane/{id}
url: "{{ url('plane') }}/"+id,
GET /plane index plane.index
GET /plane/create create plane.create
POST /plane store plane.store
GET /plane/{plane} show plane.show
GET /plane/{plane}/edit edit plane.edit
PUT|PATCH /plane/{plane} update plane.update
DELETE /plane/{plane} destroy plane.destroy