Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Laravel
  3. Eloquent Sortable

Eloquent Sortable

MITPHP5.0.1

A Laravel package that adds sortable behavior to Eloquent models with automatic ordering and query scopes.

Visit WebsiteGitHubGitHub
1.5k stars138 forks0 contributors

What is Eloquent Sortable?

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.

Target Audience

Laravel developers building applications that require ordered data, such as task lists, menu items, galleries, or any interface where users can rearrange items.

Value Proposition

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.

Overview

Sortable behaviour for Eloquent models

Use Cases

Best For

  • Managing ordered lists in Laravel admin panels
  • Implementing drag-and-drop sorting for frontend components backed by Eloquent
  • Creating prioritized content like FAQs or testimonials with manual ordering
  • Handling sortable galleries or portfolios where sequence matters
  • Building nested or grouped sortable items (e.g., tasks per project)
  • Adding custom order columns to Eloquent models without reinventing the wheel

Not Ideal For

  • Projects requiring hierarchical or nested sorting structures (e.g., multi-level categories or tree menus)
  • Applications built with non-Laravel frameworks or alternative ORMs like Doctrine
  • High-concurrency systems where race conditions in order updates are a concern without manual locking
  • Datasets with millions of rows where frequent reordering could lead to performance bottlenecks

Pros & Cons

Pros

Automatic Order Management

New records automatically receive the next highest order value, eliminating manual sequence setup as shown in the README's default behavior.

Comprehensive Reordering API

Provides methods like setNewOrder for batch updates and moveOrderUp for individual adjustments, offering fine-grained control without custom queries.

Group-Aware Sorting

Supports sorting within scopes via the buildSortQuery method, ideal for per-user or per-category lists without global order conflicts.

Event-Driven Hooks

Dispatches EloquentModelSortedEvent after sorting, enabling seamless post-sort actions like cache clearing, as detailed in the event section.

Cons

No Built-In Frontend

Only handles backend logic; developers must separately implement UI components for drag-and-drop or manual reordering, adding development overhead.

Integer Order Limitations

Relies on integer columns for ordering, which can create gaps after deletions and may require periodic reindexing, unlike floating-point systems.

Performance on Large Datasets

Methods like setNewOrder execute multiple UPDATE queries, potentially slowing down with thousands of records due to lack of bulk optimization.

Frequently Asked Questions

Quick Stats

Stars1,516
Forks138
Contributors0
Open Issues0
Last commit29 days ago
CreatedSince 2014

Tags

#eloquent#package#database#laravel#sorting#trait#php#sort#order-management

Built With

C
Composer
P
PHP
L
Laravel

Links & Resources

Website

Included in

Laravel13.0k
Auto-fetched 1 day ago

Related Projects

LiveWireLiveWire

A full-stack framework for Laravel that takes the pain out of building dynamic UIs.

Stars23,556
Forks1,742
Last commit3 days ago
Debug BarDebug Bar

Debugbar for Laravel (Integrates PHP Debug Bar)

Stars19,270
Forks1,617
Last commit14 days ago
IDE HelperIDE Helper

IDE Helper for Laravel

Stars14,953
Forks1,191
Last commit15 days ago
Intervention ImageIntervention Image

PHP Image Processing

Stars14,356
Forks1,495
Last commit6 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub