[Vuejs]-I can not save values using POST method โ€“ laravel vue

0๐Ÿ‘

โœ…

Try sending form data

Here is the example for you.

var urlEvent = '/dashboard/newEvent';

var form_data = new FormData();
form_data.append('id',this.user.id);
form_data.append('title',this.title);

for(let coin of this.coinvalue)
    form_data.append('coin[]', coin);

for(let category of this.categoryvalue)
    form_data.append('category[]', category);

axios(urlEvent,{
    method: "post",
    data: form_data
})
.then(res => {
    console.log(ok);
})
.catch(err => {
    console.log(err.response.data);
});

If this stills gives you a 422 status code (Unprocessable entities). Then try returning $request in you controller. And check what data are actually send to the controller and what your validation is.

๐Ÿ‘คaj3sh

0๐Ÿ‘

422 means validation error so do a console.log or inspect the element on axios call and check that :

 'title'         : this.title,
 'coin'          : this.coinvalue,
 'category'      : this.categoryvalue,

Are not empty, cause right now some data from above is missing since its a 422 validation exception.

๐Ÿ‘คLeo

Leave a comment