In this episode, we're diving into how to handle pagination with Inertia.js and Vue. We start by first forcing our pagination to just one item per page (yep, for testing!), and you'll notice of course, there are no navigation controls yet. If we tweak the page manually, we do see different items, but that’s not user-friendly, so let’s fix that.
We decide to create a reusable Pagination
component since we'll want this on other parts of our forum app. We nestle it nicely under our shared components. Next, we explore the data Laravel gives us for paginated discussions: a meta
object holds all the details including those handy navigation links. Since we're now in Vue instead of Blade, we need to render these ourselves.
Step by step, we build out the component—importing necessary bits, iterating through the links Laravel gives us, and making sure each pagination button properly routes using Inertia. Once everything's wired up, we can click next, previous, or specific page numbers and smoothly navigate without a page reload.
With the logic working, we style the pagination bar to make it look tidy and user-friendly. We polish the appearance, highlight the current page, and gray out links that can't be clicked (like "previous" on the first page). We even handle those pesky HTML entities for arrows and clean up the edge cases, like making sure nothing weird shows up if the paginated list is empty.
By the end of the video, you’ll have a good-looking, fully functional, and reusable pagination component for your Inertia-powered app — no more ugly, hacky navigation!