Back to Blog

Laravel Pagination: paginate(), simplePaginate(), and cursorPaginate()

When building modern Laravel applications, dealing with large sets of data is common — whether you’re showing product listings, blog posts, user records, or order histories. Laravel makes it easy to split data into pages using pagination. Laravel offers three powerful pagination methods: paginate() simplePaginate() cursorPaginate() While they seem similar, each has its own use […]

Laravel Pagination: paginate(), simplePaginate(), and cursorPaginate()

When building modern Laravel applications, dealing with large sets of data is common — whether you're showing product listings, blog posts, user records, or order histories. Laravel makes it easy to split data into pages using pagination.

Laravel offers three powerful pagination methods:

  • paginate()
  • simplePaginate()
  • cursorPaginate()

While they seem similar, each has its own use case, performance advantage, and impact on UX. Let’s break it down.


🔢 1. paginate()

✅ What it does:

  • Retrieves data with count of total records.
  • Shows page numbers and full pagination info.
  • Performs an additional SQL query to get COUNT(*).

🧠 Use Case:

You want a traditional page-based navigation system, like:

  • Admin panel showing users: "Page 1 of 50"
  • Blog with numbered pagination

🧪 Example:

$users = User::paginate(15);

🔍 Output:

  • Current page
  • Total items
  • Last page
  • Next/previous page URLs
{{ $users->links() }}

📉 Downside:

  • Can be performance-heavy on large datasets because of the extra COUNT query.

⚡ 2. simplePaginate()

✅ What it does:

  • Retrieves data like paginate(), but doesn’t count total records.
  • Only shows "Next" and "Previous" buttons.

🧠 Use Case:

When you don’t need total pages or count, but want simple navigation:

  • Infinite scrolls
  • Mobile-friendly pagers
  • Lightweight UIs

🧪 Example:

$posts = Post::simplePaginate(10);

🔍 Output:

  • No total page info
  • Faster than paginate() due to no COUNT query
{{ $posts->links() }}

🚀 3. cursorPaginate()

✅ What it does:

  • Uses a cursor-based approach instead of offset.
  • More efficient for large data or real-time loading.
  • Avoids skipping or duplication in frequently changing datasets.

🧠 Use Case:

Best for:

  • Chat systems or live feeds
  • Large product lists
  • APIs or infinite loaders
  • Data that changes quickly (less chance of missing/duplicate records)

🧪 Example:

$products = Product::orderBy('id')->cursorPaginate(20);

🔍 Output:

  • No total pages or total records
  • Uses nextCursor() for pagination
  • Very fast for large datasets
{{ $products->links() }}

⚖️ Comparison Table

Feature paginate() simplePaginate() cursorPaginate()
Total Record Count ✅ Yes ❌ No ❌ No
Page Numbers ✅ Yes ❌ No ❌ No
Performance 🟡 Medium ✅ Fast ✅✅ Very Fast
Suitable for APIs ⚠️ Only with limits ✅ Yes ✅✅ Ideal
Duplicate-safe ❌ No ❌ No ✅ Yes (cursor-safe)
Use with Live Data ❌ Risky ❌ Risky ✅ Best option

🧑‍💼 Real-World Example: E-commerce Admin Panel

Imagine you're building a product management dashboard for a large store.

  • The admin wants to see all products with total counts and page numbers → Use paginate().
  • On the customer-facing product listing, where you only need to show a list without caring about total records → Use simplePaginate().
  • On a mobile app or infinite scroll page, where thousands of products are loaded efficiently → Use cursorPaginate().

🧠 Final Thoughts

Choosing the right pagination method can greatly impact:

  • Performance
  • User experience
  • API response times

➡ Use paginate() when you need full pagination info.
➡ Use simplePaginate() for lightweight, fast pages without needing the total.
➡ Use cursorPaginate() for speed and accuracy on massive or frequently-updated datasets.


🔗 Bonus Tips:

  • All pagination methods can be customized using:
->withQueryString()
->appends(['search' => 'shoes'])

📌 Conclusion

Laravel gives you the flexibility to handle any pagination scenario — from traditional web pages to real-time APIs. Use the method that best suits your use case and watch your app's performance and user satisfaction soar 🚀.