Polyscope - The agent-first dev environment for Laravel

Drag-and-Drop Sorting for Eloquent Models with Reorderable for Laravel

Last updated on by

Drag-and-Drop Sorting for Eloquent Models with Reorderable for Laravel image

Laravel Reorderable by Richie McMullen adds drag-and-drop sorting to any Eloquent model. It ships with ready-made Blade and Livewire components, persists new positions automatically via a package route, and supports scoping sort order within a parent group.

This package works by applying the HasSortOrder trait and ReorderableContract to your model:

use Atomcoder\LaravelReorderable\Contracts\ReorderableContract;
use Atomcoder\LaravelReorderable\Traits\HasSortOrder;
 
class Task extends Model implements ReorderableContract
{
use HasSortOrder;
 
protected $fillable = ['title', 'project_id', 'sort_order'];
protected string $sortColumn = 'sort_order';
 
public function getReorderLabel(): string
{
return $this->title;
}
}

The trait automatically assigns a sort position on creation and adds an ordered() query scope so you fetch records in the right sequence.

Blade and Livewire Components

The package covers both rendering approaches. Drop an @include into a Blade view, or use the Livewire component — both accept the same options:

Blade:

@include('reorderable::components.list', [
'items' => $tasks,
'modelClass' => App\Models\Task::class,
'groupColumn' => 'project_id',
'groupValue' => $project->id,
'title' => 'Reorder Tasks',
'listId' => 'project-tasks-list',
])

Livewire:

<livewire:reorderable-list
:items="$tasks"
model-class="App\Models\Task"
group-column="project_id"
:group-value="$project->id"
title="Reorder Tasks"
list-id="project-tasks-list"
/>

When a user drags an item, the component posts the new order to POST /reorderable/update, which updates the sort column for each record in the database.

Grouped Reordering

The package restricts sort operations to a parent group, so dragging tasks in one project doesn't affect tasks in another. The same scoping is available programmatically via moveToPosition() or reorderFromArray():

$task->moveToPosition(
position: 2,
groupColumn: 'project_id',
groupValue: $task->project_id,
);
 
Task::reorderFromArray(
orderedIds: [8, 3, 5, 1],
groupColumn: 'project_id',
groupValue: 12,
);

The Generator Command

Instead of wiring up the trait and configuration by hand, reorderable:make scaffolds everything from the command line:

php artisan reorderable:make Task --table=tasks --label=title --column=sort_order

The --label option controls which attribute shows in the drag-and-drop UI, and --column sets the sort column name if you're not using the default sort_order.

Authorization and Events

The configuration accepts a closure to gate access to the update route, so you can tie it to a policy or role check:

'authorize' => function ($request, string $modelClass): bool {
return $request->user()?->can('manage-content') ?? false;
},

After a successful reorder, the package dispatches ItemsReordered, which carries the model class, the ordered IDs, and the group column and value — useful for cache busting or audit logging.

Requirements

The package requires PHP 8.3+, Laravel 13+, and Livewire 4+.

To learn more, view the source on GitHub.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech
Shift logo

Shift

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

Shift
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
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
SerpApi logo

SerpApi

Access real-time search engine results through a simple API—no more scraping headaches! Use it for AI applications, SEO tools, product research, travel information, and more

SerpApi
PhpStorm logo

PhpStorm

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

PhpStorm
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
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

The latest

View all →
Ship AI with Laravel: Real-Time Streaming Chat UI with Livewire image

Ship AI with Laravel: Real-Time Streaming Chat UI with Livewire

Read article
Frontend Nation 2026 Returns June 3-4 with Laravel in the Lineup image

Frontend Nation 2026 Returns June 3-4 with Laravel in the Lineup

Read article
Use a Google Sheet as Your Laravel Database with the Google Sheets Database Driver image

Use a Google Sheet as Your Laravel Database with the Google Sheets Database Driver

Read article
Larapanda: A Type-Safe Lightpanda Browser SDK for Laravel image

Larapanda: A Type-Safe Lightpanda Browser SDK for Laravel

Read article
Generate HTML Password Rules Attribute in Laravel 13.9.0 image

Generate HTML Password Rules Attribute in Laravel 13.9.0

Read article
DHH Joins Laravel Live Denmark 2026 for Fireside Chat with Taylor Otwell image

DHH Joins Laravel Live Denmark 2026 for Fireside Chat with Taylor Otwell

Read article