crissi / laravel-cursor-pagination-with-null-values
Laravel cursor pagination with null values
Fund package maintenance!
crissi
Requires
- php: ^7.4|^8.0
- illuminate/contracts: ^8.41
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- nunomaduro/collision: ^5.3
- orchestra/testbench: ^6.15
- pestphp/pest: ^1.18
- pestphp/pest-plugin-laravel: ^1.1
README
For the Query builder and the Eloquent Query builder
Adds a new method to allow cursor pagination to work with column that can have null values using the same method argument signature as Laravel's current cursorPaginate-method.
Why? Columns with null values are not supported in the current Laravel implementation as mentioned in Laravel's docs.
https://laravel.com/docs/8.x/pagination#cursor-vs-offset-pagination
Currently works for database drivers: sqlite, mysql and sqlserver
Installation
You can install the package via composer:
composer require crissi/laravel-cursor-pagination-with-null-values
You can publish the config file with:
php artisan vendor:publish --provider="Crissi\LaravelCursorPaginationWithNullValues\LaravelCursorPaginationWithNullValuesServiceProvider" --tag="laravel-cursor-pagination-with-null-values-config"
This is the contents of the published config file:
return [ 'method_name' => 'cursorPaginateWithNullValues' ];;
Usage
Before:
return User::orderBy('id')->cursorPaginate(5);
After:
return User::orderBy('id')->cursorPaginateWithNullValues(5);
return User::orderBy('nullable_column')->orderBy('id')->cursorPaginateWithNullValues(5);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.