oddvalue / eloquent-sortable
Some additional features on top of https://github.com/spatie/eloquent-sortable
Installs: 81 318
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^8.0
- illuminate/contracts: ^10.0|^11.0
- spatie/eloquent-sortable: ^4.0
- spatie/laravel-package-tools: ^1.16.4
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.0|^8.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^10.0
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-11-08 13:00:27 UTC
README
Some additional features on top of Spatie's Eloquent Sortable
This package is an extension of Spatie's excellent Eloquent Sortable. It adds the following additional features:
- New methods
$model->moveBefore(int|Sortable $target): void
$model->moveAfter(int|Sortable $target): void
$model->moveBetween(int|Sortable $before = null, Sortable $after = null): void
$model->moveTo(int|Sortable $newPosition): void
Note: The move methods rebuild the entire sequence so this package is not recommended for very large datasets.
Installation
You can install the package via composer:
composer require oddvalue/eloquent-sortable
Usage
Implement the interface and use the trait.
class MyModel extends Model implements \Oddvalue\EloquentSortable\Sortable { use \Oddvalue\EloquentSortable\SortableTrait; }
# New model automatically sorted to the end of the list upon creation $model = MyModel::create(['title' => 'foo']); # Move the model before the 5th item in the list $model->moveBefore(MyModel::where('order_column', 5)->first()); // OR $model->moveBefore(5); # Move the model after the 5th item in the list $model->moveAfter(MyModel::where('order_column', 5)->first()); // OR $model->moveAfter(5); # Move the model between the 5th and 6th item in the list $model->moveBetween( MyModel::where('order_column', 5)->first(), MyModel::where('order_column', 6)->first() ); // OR $model->moveBetween(5, 6); # This is useful when using a javacript library that provides the node before # and after the location an item is dropped # Move the model to the 5th item in the list $model->moveTo(MyModel::where('order_column', 5)->first()); // OR $model->moveTo(5);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.