crissi/laravel-cursor-pagination-with-null-values

Laravel cursor pagination with null values

v1.0.0 2021-10-23 17:59 UTC

This package is auto-updated.

Last update: 2024-04-09 19:38:48 UTC


README

For the Query builder and the Eloquent Query builder

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.