From the course: Building Laravel and Vue.js 2 Web Apps

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Displaying model validation errors

Displaying model validation errors

From the course: Building Laravel and Vue.js 2 Web Apps

Start my 1-month free trial

Displaying model validation errors

- [Instructor] Next we'll hook up our menu item form to the API and display the validation errors in our view component. So first, we'll just use Axios in our menu item save method to make a post request to /api/menu-items/add that route that we set up, and all we have to pass for data is this.item. For now, let's see if we can just log the response to the console in the then callback. So I'm just going to do res with an arrow function console.log res. Remember, our request won't be valid without an image, so we're expecting at least one error message that mentions that, so I'll just create any item, and this pizza's going to be an entree, and now let's open up the developer tools, 'cause we're going to be looking at the console, and when I click Save, I don't see anything logged, but I see that there was an uncaught error, and I got a response of 422 Unprocessable Entity. If I go over to the Network tab, under XHR, and look at that, I can actually see the validation error in here…

Contents