Offset vs Cursor Pagination in Laravel [In-Depth Guide]
Introduction Recently, I made a pull request on Github to add cursor pagination to Laravel. This Laravel feature will be released today! This post describes both offset and cursor pagination strategies, and describes which one to use depending on your use case. Offset Pagination Offset pagination is one of the most widely used pagination techniques in the world today. Laravel’s paginate and simplePaginate methods on the Eloquent and database query builder classes use offset pagination under the hood. Consider the following Laravel code to paginate the users table: Under the hood, offset pagination fires a query that uses the offset clause. For example, here’s the query fired if you were to visit the 2nd page: Cursor Pagination Cursor pagination is a high performant pagination technique often used for large data-sets, infinite scrolling and APIs (more on that later). Today’s Laravel release adds the cursorPaginate method to the Eloquent and database query builder classes, which uses cursor pagination under the hood. Here’s how we can cursor paginate the users table in Laravel: The code is exactly the same way as simplePaginate, except that it fires a different query. Here’s the query fired by cursor pagination if you were to visit the … Continue reading Offset vs Cursor Pagination in Laravel [In-Depth Guide]
Copy and paste this URL into your WordPress site to embed
Copy and paste this code into your site to embed