Package

Spatie Eloquent Sortable

Sortable behaviour for eloquent models

Package

spatie/eloquent-sortable

View on GitHub →

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 →

Spatie Eloquent Sortable Related Articles

Log User Activity in Your Laravel App with Activity Log v5  image

Log User Activity in Your Laravel App with Activity Log v5

Read article
Laravel Event Projector Released image

Laravel Event Projector Released

Read article
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Pushsilver logo

Pushsilver

Pushsilver is simple invoicing for freelancers and small studios — send polished invoices, automate reminders, and get paid on time without the bloat.

Pushsilver
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift