1

我正在尝试将补丁请求从我的 Vuetify 数据表发送到 Laravel,然后发送到 mySQL DB。

这是来自我的 controller.php、我的 api.php 和实际 Vuetify 文件的各种代码片段:

api.php:

Route::patch('machines/{id}', [
    'as'   => 'machines/{id}',
    'uses' => 'MachineController@update'
]);

机器控制器.php

$machines = Machine::find($request->id)->update();

实际的 axios 补丁要求。在 .vue 文件中:

Object.assign(this.machines[this.editedIndex], this.editedItem);

axios.patch("machines/" + this.editedItem.id, {
    editedItem: this.editedItem
})

在望远镜有效载荷部分,我得到了更新的对象,但我也得到了一条消息:

“SQLSTATE [23000]:违反完整性约束:1048 列不能为空。

对于所有列。

我也尝试过这种语法作为补丁方法:

if (this.editedIndex > -1) {
    Object.assign(this.machines[this.editedIndex], this.editedItem);
    axios
        .patch("machines/" + this.editedItem.id)
        .then(res => {
            this.editedItem = Object.assign({}, this.editedItem);
        })
        .catch(err => {
            console.log(err);
        });
} else {
    this.machines.push(this.editedItem);
}
this.close();

我尝试像这样设置控制器:

$machines = Machine::find($request->id);
$machines->machine_number = $request->input('machine_number');
$machines->machine_name = $request->input('machine_name');
$machines->machine_company = $request->input('machine_company');
$machines->machine_division = $request->input('machine_division');
$machines->machine_center = $request->input('machine_center');
$machines->machine_speed = $request->input('machine_speed');
$machines->save();

但我仍然遇到同样的错误。有人可以帮助我,或者至少指出我正确的方向吗?谢谢!

4

1 回答 1

1

我已经解决了我的问题:我在axios.patch()请求中传递了空对象,因为我设置错误。我已将对象的结构更改为key:value对,瞧,它起作用了!

于 2019-05-13T20:22:48.817 回答