Unlike offset based pagination, which includes a page number in the query string of the URLs generated by the paginator, cursor based pagination places a "cursor" string in the query string.
This method of pagination is particularly well-suited for large data-sets and "infinite" scrolling user interfaces. While paginate and simplePaginate create queries using the SQL "offset" clause, cursor pagination works by constructing "where" clauses that compare the values of the ordered columns contained in the query, providing the most efficient database performance available amongst all of Laravel's pagination methods. $perPage = 15, $columns =, $pageName = 'users'
![octane render demo octane render demo](https://advokat-kononchuk.com.ua/wp-content/uploads/2021/09/5e9761.jpg)
To resolve this conflict, you may pass the name of the query string parameter you wish to use to store the paginator's current page via the third argument provided to the paginate, simplePaginate, and cursorPaginate methods: use App\Models\User However, if both paginator instances use the page query string parameter to store the current page, the two paginator's will conflict. Sometimes you may need to render two separate paginators on a single screen that is rendered by your application. Similarly, you may use the cursorPaginate method to cursor paginate Eloquent models: $users = User::where('votes', '>', 100)->cursorPaginate(15) You may also use the simplePaginate method when paginating Eloquent models: $users = User::where('votes', '>', 100)->simplePaginate(15)
![octane render demo octane render demo](https://res.infoq.com/presentations/reactive-spring-sao-paulo-2019/en/slides/sl1-1567201776687.jpg)
Of course, you may call the paginate method after setting other constraints on the query, such as where clauses: $users = User::where('votes', '>', 100)->paginate(15) As you can see, the syntax is nearly identical to paginating query builder results: use App\Models\User In this example, we will paginate the App\Models\User model and indicate that we plan to display 15 records per page. Therefore, if you only need to display simple "Next" and "Previous" links in your application's UI, you may use the simplePaginate method to perform a single, efficient query: $users = DB::table('users')->simplePaginate(15) However, if you do not plan to show the total number of pages in your application's UI then the record count query is unnecessary. This is done so that the paginator knows how many pages of records there are in total. The paginate method counts the total number of records matched by the query before retrieving the records from the database. In this case, let's specify that we would like to display 15 items per page: DB::table('users')->paginate(15) In this example, the only argument passed to the paginate method is the number of items you would like displayed "per page". This value is automatically detected by Laravel, and is also automatically inserted into links generated by the paginator. By default, the current page is detected by the value of the page query string argument on the HTTP request.
![octane render demo octane render demo](https://cdn.flippednormals.com/wp-content/uploads/2019/11/01092756/Demo_01.jpg)
The paginate method automatically takes care of setting the query's "limit" and "offset" based on the current page being viewed by the user. The simplest is by using the paginate method on the query builder or an Eloquent query. There are several ways to paginate items. Laravel's paginator is integrated with the query builder and Eloquent ORM and provides convenient, easy-to-use pagination of database records with zero configuration.īy default, the HTML generated by the paginator is compatible with the Tailwind CSS framework however, Bootstrap pagination support is also available. We hope Laravel's approach to pagination will be a breath of fresh air. In other frameworks, pagination can be very painful.