I am using Larvel 5.3 with VueJS@2 and Axios to perform post ajax request to server.
My problem is that I am unable to get laravel form validation errors. while debugging i found that firebug console was showing 422 (Unprocessable Entity) error and that is Natural because server isn't getting the expected values. But, I need to get those validation errors and show at my form.
Here is my VueJS Part
new Vue({
el: '#blogWrap',
data: {
formInputs: {},
formErrors: {}
},
methods: {
onSubmit: function () {
var csrfToken = document.querySelector('input[name="_token"]').value;
console.log(this.formInputs);
axios.post("/createpost", this.formInputs, {
headers: {'X-CSRF-TOKEN': csrfToken }
})
.then(function (response) {
console.log(response);
})
.catch(function (data, status, request) {
console.log(data);
this.formErrors = data.data;
});
}
}
})
i follwed the following link but unable to solve 422 error. http://taha-sh.com/blog/setting-up-ajax-validation-with-laravel-vuejs-in-no-time
<span v-if="formErrors.title">{{ formErrors.title }}</span>in your template code for each form field.