A Laravel package that adds sortable behavior to Eloquent models with automatic ordering and query scopes.
Eloquent Sortable is a Laravel package that adds sortable behavior to Eloquent models. It automatically manages an order column to sequence records, provides methods for reordering, and includes a query scope to fetch items in order. This solves the problem of manually handling sort positions in databases for features like drag-and-drop lists or prioritized content.
Laravel developers building applications that require ordered data, such as task lists, menu items, galleries, or any interface where users can rearrange items.
Developers choose Eloquent Sortable because it integrates natively with Eloquent, reduces boilerplate code for sorting logic, and offers a clean, trait-based API with features like grouped sorting and event hooks, making it more flexible than basic implementations.
Sortable behaviour for Eloquent models
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
New records automatically receive the next highest order value, eliminating manual sequence setup as shown in the README's default behavior.
Provides methods like setNewOrder for batch updates and moveOrderUp for individual adjustments, offering fine-grained control without custom queries.
Supports sorting within scopes via the buildSortQuery method, ideal for per-user or per-category lists without global order conflicts.
Dispatches EloquentModelSortedEvent after sorting, enabling seamless post-sort actions like cache clearing, as detailed in the event section.
Only handles backend logic; developers must separately implement UI components for drag-and-drop or manual reordering, adding development overhead.
Relies on integer columns for ordering, which can create gaps after deletions and may require periodic reindexing, unlike floating-point systems.
Methods like setNewOrder execute multiple UPDATE queries, potentially slowing down with thousands of records due to lack of bulk optimization.