How to Use Pagination in Laravel: A Practical Guide for Web and API Developers
When was the last time you scrolled through a never-ending list of items on a website or app and felt overwhelmed? That’s exactly what pagination solves.
In Laravel, pagination isn’t just a tool, it’s a superpower. Whether you’re building a traditional web app, a modern API, or an admin panel with thousands of records, Laravel gives you a clean, efficient, and developer-friendly way to break down large datasets into bite-sized, user-friendly chunks.
In this blog, we’ll walk through everything you need to know about how to use pagination in Laravel as of 2025, complete with hands-on examples, best practices, and real-world use cases.
Why Pagination Matters (and Why Laravel Nails It)
At its core, pagination is the practice of splitting up data across multiple pages. Instead of overwhelming users with a data dump, you give them manageable sets to scroll or navigate through.
Why it’s important:
Reduces page load time
Boosts performance (especially for large datasets)
Makes UX cleaner and more intuitive
Laravel takes care of most of the heavy lifting for you, whether it’s generating SQL limits or creating beautiful, responsive pagination links.
Laravel Pagination Types Explained
Laravel gives you three powerful methods for pagination. Each is optimized for different use cases:
Let’s break them down in practice.
A. Implementing Basic Pagination in Laravel (Blade Example)
Let’s walk through paginating a list of blog posts.
1. Create the Model and Seed Data
Assume your PostFactory creates 100+ dummy blog posts.
2. Add Pagination Logic to Controller
3. Display Paginated Posts in Blade View
Laravel uses Tailwind CSS pagination views by default (as of Laravel 11):
That’s it. Laravel generates the HTML and handles query strings like ?page=2.
B. Dynamic Pagination with Query Parameters
Want to let users control how many items they see per page? Easy.
1. Modify Controller:
2. Blade View Snippet:
C. Paginating API Responses (with JSON)
If you're building APIs with Laravel, pagination is just as seamless. To understand how to use pagination in Laravel API, simply apply the paginate() method to your Eloquent queries, and Laravel will return a JSON response containing data, links, and meta, making it easy to build paginated endpoints for front-end consumption.
Controller:
Sample Response:
Want more control? Wrap it in a Resource Collection.
Inside your PostCollection, you can customize the structure and metadata.
D. Performance-First: Using cursorPaginate() for Scalability
If you’re building an infinite scroll or a mobile app that streams data, cursorPaginate() is a game-changer.
Why It’s Better:
Doesn’t need count(*)
Works well with real-time or ever-growing datasets
Smooth experience for users
Controller Example:
Important:
You must use a unique, indexed, and sequential column for ordering (usually id or created_at).
E. Paginating Relationships
Need to paginate a user’s posts?
Or eager-load related data:
Laravel handles pagination alongside relationships gracefully.
F. Bonus: Livewire Pagination (Reactive Laravel)
Livewire, Laravel’s reactive UI framework, makes pagination even more dynamic, no JavaScript required.
Setup:
In your Livewire component:
In Blade:
Now, pagination updates instantly, without full page reloads.
Best Practices for Pagination in 2025
Use the right method: paginate() for admin panels or dashboards, cursorPaginate() for infinite scroll or large datasets, simplePaginate() for a basic performance boost
Avoid N+1 issues: Always eager-load relationships with [with()].
Validate query parameters: Prevent edge cases with custom validation for page and per_page.
Make it responsive: Use Tailwind pagination classes or custom UI for mobile users.
Log pagination performance: On large tables, log slow queries and consider adding indexes
Common Pitfalls to Avoid
Forgetting links() in Blade → No pagination links!
Using cursorPaginate() without consistent ordering → Breaks navigation.
Overfetching data → Use select() to limit columns.
Not appending filters → Use ->appends() or lose state on pagination.
Conclusion
Pagination might seem like a small part of your app, but it has a huge impact on performance, scalability, and user experience.
Laravel continues to make it dead simple to implement with smart defaults, flexible APIs, and out-of-the-box support for everything from Blade to JSON APIs.
If you’re building a modern web app and want it done right, it helps to hire Laravel developers or team up with a Laravel development company that knows how to make things fast, scalable, and easy to maintain.