Laravel 6 - 控制器中的更新函数 运行 但模型未传递给控制器

Laravel 6 - Update function in controller ran but the model is not passed to the controller

我想更新来自 background_check_batches table 的记录。所做的是列出所有记录,每个记录都有一个可以更改的 status 属性(列)。单击 status 值将提示弹出模式以更新该值。由于有多个记录共享一个模型,因此使用js更改了表单的动作。这里的问题是提交表单时,收到了请求的数据,但没有收到 BackgroundCheckBatch 模型 ID。我以前做过这种相同的任务,但由于某种原因它不起作用。以下是我的代码。

web.php

Route::put('/admin/dashboard/background-request/{backgroundrequest}', 'BackgroundCheckBatchController@update')->name('update');

status.blade.php ()

{!! Form::open(['action' => ['BackgroundCheckBatchController@update', -1], 'method' => 'POST', 'id' => 'adminBackgroundCheckStatusModalForm']) !!}

            @csrf
            @method("PUT")

            <div class="modal__content">
                <select class="table_custom_select" id="Status" name="status">
                        <option class="table_custom_select_pending" value="Pending">Pending</option>
                        <option class="table_custom_select_progress" value="In Progress">In Progress</option>
                        <option class="table_custom_select_complete" value="Completed">Completed</option>
                </select>
            </div>

            <div class="modal__footer">
                <button type="submit" class="button button_size_m button_theme_primary">Proceed</button>
            </div>

{!! Form::close() !!}

BackgroundcheckBatchController

public function update(Request $request, BackgroundCheckBatch $backgroundCheckBatch) {
    return $backgroundCheckBatch;
}

return $backgroundCheckBatch; 输出空数组,[] 我希望它 return URL

中提供的 ID 的 BackgroundCheckBatch

如果我return $request;,它会这样输出:

{
    _token: "Ax789Dr4VXFVE1vpjtKhEWdBjdCZqARDaNQnk7K8",
    _method: "PUT",
    status: "Completed"
}

如果我没有提供足够的细节请通知我

您正在使用 implicit binding,但它不起作用,因为您的路由参数与控制器方法的参数名称不匹配,

将您的路由参数更改为 $backgroundCheckBatch 的 snake_case(控制器方法的类型提示参数名称):

Route::put('/admin/dashboard/background-request/{background_check_batch}', 'BackgroundCheckBatchController@update')->name('update');

如果您想使用路由模型绑定更新函数中的参数名称应与路由参数匹配:

public function update(Request $request, BackgroundCheckBatch $backgroundrequest) {
    return $backgroundrequest;
}