Reputation: 437
I am using Laravel 5.8 and Vue.js 2, this is my .vue file:
let data = new FormData();
data.append('name', this.name);
data.append('image',this.image)
data.append('_method', 'PATCH');
axios.patch('/url/' + this.id, data)
.then(({data}) => {
})
.catch((error) => {
});
Route
Route::patch('/url/{id}', 'CarsController@update');
Error
Integrity constraint violation: 1048 Column 'name' cannot be null.
But when I change the method to POST, both in my vue file and web.php it works, what is happening? I need to use both methods: post for new data and patch for updating. What can I do?
Upvotes: 1
Views: 2417
Reputation: 1639
Http patch
method does not support FormData
. So either submit JSON request or change your route method to post
. Also, if patch
method is must have then you can submit axios.post
with additional attribute _method: 'patch'
which then can handle FormData
request.
Upvotes: 6