From the course: Building a Website with Laravel, React.js, and Inertia
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Creating PostController index and store methods - Laravel Tutorial
From the course: Building a Website with Laravel, React.js, and Inertia
Creating PostController index and store methods
- [Instructor] Let's look at the post controller now. As you can see, we have the index, store, show, update and destroy methods already scaffolded for us. This is what Laravel did when we created the post resource. We will do the bare minimum here to get all endpoints working, so we won't do any filtering, pagination, or any sort of ordering now. That would be beyond the scope of this course. For the index method we will get all posts from the database and return them as API resource collection. Collection because we are returning more than one resource, more than one post. Don't forget to import a post resource here at the top. To see if this worked we need to check the endpoint in the browser. As I said earlier, if you want to know or be reminded of what endpoint is we can run php artisan route:list in the terminal. The endpoint to get all posts is api/posts. So, in the browser I'll go to linkedin-block.test/api/posts. And here are all our posts. Remember the post resource and how…
Contents
-
-
-
(Locked)
Getting started: Creating a new Laravel project1m 59s
-
(Locked)
Creating a Post resource1m 51s
-
Creating a seeder and a factory1m 15s
-
(Locked)
Creating Post API resource1m 27s
-
(Locked)
Creating PostController index and store methods4m 25s
-
(Locked)
Creating PostController show, update, and destroy methods2m 14s
-
(Locked)
Challenge: Testing API Endpoints with PHPUnit1m 55s
-
(Locked)
Solution: Testing API Endpoints with PHPUnit3m 57s
-
(Locked)
-
-
-