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
From the course: Building Laravel and Vue.js 2 Web Apps
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Protecting admin pages with gates4m 30s
-
(Locked)
Installing and configuring Vue Router4m 56s
-
(Locked)
Using props and router-link4m 50s
-
(Locked)
Enabling Vue Router history mode5m 38s
-
(Locked)
Validating form submissions5m 23s
-
(Locked)
Displaying model validation errors5m 43s
-
(Locked)
Managing file uploads6m 50s
-
(Locked)
Working with related models4m 39s
-
(Locked)
Building a list view with detail links6m 4s
-
(Locked)
Reusing form components3m 56s
-
(Locked)
Using Laravel form requests3m 48s
-
(Locked)
Using Vue Router navigation guards3m 37s
-
-
-