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

Laravel Blade Sortable image

Laravel Blade Sortable

Read article
Media Library Pro: Vue, React and Blade components to handle uploads (sponsor) image

Media Library Pro: Vue, React and Blade components to handle uploads (sponsor)

Read article
Spatie Shares Their Coding Guidelines as AI Skills image

Spatie Shares Their Coding Guidelines as AI Skills

Read article
Image Optimization With Spatie Laravel Image Optimizer image

Image Optimization With Spatie Laravel Image Optimizer

Read article
Driver-Based Architecture in Spatie's Laravel PDF v2 image

Driver-Based Architecture in Spatie's Laravel PDF v2

Read article
New Major Versions of Spatie Image and Laravel Media Library Released image

New Major Versions of Spatie Image and Laravel Media Library Released

Read article

Let your users buy domains without leaving your app

If your Laravel app gives users a site, a storefront, or a workspace, they’ll eventually want their own domain. The name.com API lets them search, register, and connect one without leaving your product. It’s a clean REST API, so Laravel’s HTTP client is all you need.

Let your users buy domains without leaving your app

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

PhpStorm

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

PhpStorm

Shift

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

Shift

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

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum