Package
Spatie Eloquent Sortable
Sortable behaviour for eloquent models
Overview
What Spatie Eloquent Sortable does
Spatie's Eloquent Sortable package introduces sortable behavior to Eloquent models, automating the ordering process within Laravel applications.
The package addresses a common need in web applications: dynamically ordering database records. By implementing the Sortable interface and using the SortableTrait, developers can ensure that new records automatically receive the correct position based on an order column, streamlining data management and organization.
With Eloquent Sortable, the order column of a new model is assigned by incrementing the highest existing order value. This automation saves time and reduces errors associated with manual ordering. Additionally, the package provides a query scope that retrieves records in the correct order, enhancing data retrieval processes for applications that require ordered outputs.
Developers have the flexibility to modify the order of records with simple methods like setNewOrder and setNewOrderByCustomColumn. These capabilities allow for reordering based on different criteria, including custom columns or specific starting points. The package also includes utility methods to move an item up or down in the order or to the start or end, adding further convenience.
Eloquent Sortable fits naturally into the Laravel ecosystem, leveraging both the framework's strengths and the PHP language's features. It's an ideal choice for developers who need an intuitive method to manage ordered lists in their database while minimally altering their existing models.
This overview was generated by AI from the package README and may not reflect the latest release.
Read the full README →