Am getting this 422 (Unprocessable Entity) error while trying to do a POST request using Laravel and Vue-resource. I currently have the following codes:
**My Controller **
422 should not be seen as an "error", it's simply the response code laravel returns when validation fails.
If you were to inspect the element in lets say firebug, you would see the validation rules there of the failed request.
First, pass your form data in your Ajax call, but even then, you'll get the validation error (422) because you're requiring a title and a description but your form is passing "project-title" and "project-description", so you're failing on the "required" validation.
To "catch" and show the errors, you could have a data variable in your component named "formError" that is initialized to an empty string, then in the error function of your Ajax call, you could set the value of that variable from the response, then have an error div that is shown conditionally depending on the "formError" variable being set.
@clay Actually my form fields and the validation rules are the same, while pasting the code here I told out some part and forgot to update the remaining as appropriate.
Anyways, irrespective of the form fields and validation rules, the validation always fail on Ajax submission but works well with non-ajax submission.
this.$http.post('api/projects', project).then(function (response) {
console.log(response.data);
}, function (error) {
console.log(error.response.data); <--- Go down one more stream @mezie.
});