From the course: Laravel Essential Training

Unlock the full course today

Join today to access over 25,000 courses taught by industry experts.

Add pagination and clean up the index view

Add pagination and clean up the index view - Laravel Tutorial

From the course: Laravel Essential Training

Add pagination and clean up the index view

Currently, we're fetching all the notes of the user and passing them to the view. But what if the user has hundreds of notes? We surely need pagination. Since it's very common to add pagination, Laravel has made it very easy for us. Just replace get here with paginate and pass the count of items you'd like to display in a page. And just for demonstration, let me add 1 here. Save the file and refresh. As you can see, we have one single note, but we also need the links here for navigation. That's also easy. Just go to the view first. At the end, after foreach, you simply have to add $notes->links. Like so. And now refresh. Look at that. Out of the box, we get pagination. And all of this is styled using Tailwind CSS and all the links work as expected. If you wish to customize the styling, you can do so by passing your own pagination view right here. All right, now that we know it works, let's go back to our controller and change this to 5. Back to the browser. This view looks fine right…

Contents