In this episode, we take a look at how to properly show a list of posts in our app using Laravel's API resources. At first, we fetch all the posts straight from the database and send them to our frontend component, but we quickly notice that this approach sends more data than we probably want—like timestamps and other internal columns that aren't really necessary for display.
To fix this, we introduce Laravel's API resources to customize exactly which fields get sent down to the client. This gives us full control over the structure of the data, so we can limit it to just the ID and body, for example. We also tweak the default wrapping behavior so we get a simple array of posts, making things easier to work with on the frontend.
We then head back to our Vue component, update it to loop through all the posts, and render them in a neat list. Plus, we make use of the flexibility API resources give us by customizing how the post's creation date is formatted—for example, showing '2 hours ago' instead of a full timestamp.
Finally, we see how everything ties together as a single page app: when we submit a new post, Inertia automatically refreshes the post list without a full page reload, making the experience super smooth. All in all, by the end of this episode you'll see how API resources can really help structure your data and make your frontend code cleaner.