Download the PHP package app-ark/eloquent-sortable without Composer
On this page you can find all versions of the php package app-ark/eloquent-sortable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent-sortable
Sortable behaviour for Eloquent models
This package provides a trait that adds sortable behaviour to an Eloquent model.
The value of the order column of a new record of a model is determined by the maximum value of the order column of all records of that model + 1.
The package also provides a query scope to fetch all the records in the right order.
Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
Postcardware
You're free to use this package (it's MIT-licensed), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.
The best postcards will get published on the open source page on our website.
Installation
This package can be installed through Composer.
Usage
To add sortable behaviour to your model you must:
- specify that the model will conform to
- use the trait
- specify which column will be used as the order column
Example
If you don't set a value $sortable['order_column_name']
the package will assume that your order column name will be named order_column
.
If you don't set a value $sortable['sort_when_creating']
the package will automatically assign the highest order number to a new model;
Assuming that the db-table for MyModel
is empty:
You can set a new order for all the records using the setNewOrder
-method
Optionally you can pass the starting order number as the second argument.
You can also move a model up or down with these methods:
You can also move a model to the first or last position:
You can swap the order of two models:
Tests
The package contains some integration/smoke tests, set up with Orchestra. The tests can be run via phpunit.
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Freek Van der Herten
- All Contributors
Alternatives
About Spatie
Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
License
The MIT License (MIT). Please see License File for more information.