Reputation: 147
i'm trying to send a patch request from my Vuetify data-table to Laravel & then to a mySQL DB.
Here's various code pieces from my controller.php, my api.php & the actual Vuetify file:
api.php:
Route::patch('machines/{id}', [
'as' => 'machines/{id}',
'uses' => 'MachineController@update'
]);
MachineController.php
$machines = Machine::find($request->id)->update();
the actual axios patch req. in the .vue file:
Object.assign(this.machines[this.editedIndex], this.editedItem);
axios.patch("machines/" + this.editedItem.id, {
editedItem: this.editedItem
})
In the Telescope payload section i'm getting the updated object, but i'm also getting a message:
"SQLSTATE[23000]: Integrity constraint violation: 1048 Column cannot be null.
For all the columns.
I have also tried this syntax for a patch method:
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();
And i tried setting up the controller like this:
$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();
But I'm still getting the same error. Can someone help me out, or at least point me in the right direction? Thanks!
Upvotes: 1
Views: 883
Reputation: 147
I have solved my issue: I was passing empty object with my axios.patch()
request because i've set it up wrong. I've changed the object's structure to key:value
pairs and voila, it worked!
Upvotes: 1