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

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