Download the PHP package amrnn/laravel-cursor-paginator without Composer
On this page you can find all versions of the php package amrnn/laravel-cursor-paginator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amrnn/laravel-cursor-paginator
More information about amrnn/laravel-cursor-paginator
Files in amrnn/laravel-cursor-paginator
Package laravel-cursor-paginator
Short Description Cursor pagination for Laravel
License MIT
Informations about the package laravel-cursor-paginator
Laravel Cursor Paginator
Easily have cursor based pagination in your Eloquent models and query builders, read this article to understand the benefits of cursor pagination and the problems it attempts to solve.
There's another cursor-pagination package but unfortunately it doesn't support retrieving previous pages or multi-column ordering, that's why I decided to create this one.
Features
- Automatically paginates based on columns ordering.
- Supports multi-column ordering which makes it easy to have a deterministic row sequence.
- Detects if the model has date casts.
- Mutiple cursor directions:
- before: returns the items before the cursor.
- before_i: returns the items before the cursor (including the item at the cursor).
- after: returns the items after the cursor.
- after_i: returns the items after the cursor (including the item at the cursor).
Installation
First install the package via composer:
You can optionally publish the config file:
Register service provider
The package automatically registers itself, but if you need to you can add the service provider manually.
Usage
This package provides a cursorPaginate()
method that you can invoke on your Eloquent models or query builders:
which will return something like this:
Options
You can pass an optional first argument to paginateCursor()
to specify the number of items per page (if left empty a default value from config file is used):
The package should automatically determine date casts by inspecting your model. However, if you're invoking the pagination on a plain query builder then you may need to pass a second argument which tells it about the date casts:
Multiple Columns
You can order by multiple columns and pagination should work as expected:
It's not recommended to mix directions (asc, desc) when ordering by multiple columns. Doing that would make using table indexes hard for your database.
Caveats
All the columns that you're ordering by must also appear in your select statement, for example the following won't work:
You have to do any of the following instead:
Config
License
This project is licensed under the MIT License - see the LICENSE.md file for details.