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.
Calling an API from Vue
From the course: Building Laravel and Vue.js 2 Web Apps
Calling an API from Vue
- [Instructor] Before we start making calls to the API from our Vue component, we'll need to build out this upsert action in the Category controller a bit. First, let's inject the incoming request which we can do by just creating a parameter of type, Request. We're going to need this to update all existing categories and store any new categories. We'll just be posting our categories data property from the component, so we can store that for categories, and we can access that now with request, post, categories, like that. Then we'll loop through them, for each categories, and again, I'm going to use cat as a looping variable, and we can say, if the ID isn't empty, or isn't zero, then we can use the Category::where method to find the category that has that ID, and then we can call update, passing that cat array of keys and values that we want to update for that model. Otherwise, we can just call Category::create, passing the same array of keys and values. Since Vue needs to be made…
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
-
-
-
-
Integrating a layout6m 46s
-
(Locked)
Creating a model and seeding the database4m 46s
-
(Locked)
Building views with Blade templates5m 6s
-
(Locked)
Injecting props in Vue components4m 49s
-
(Locked)
Building a CRUD component5m 9s
-
(Locked)
Managing scrolling and focus4m 18s
-
(Locked)
Protecting routes and models with policies5m 5s
-
(Locked)
Building an API with Laravel Passport5m 1s
-
(Locked)
Calling an API from Vue7m 46s
-
-
-
-