Download the PHP package atomcoder/laravel-reorderable without Composer

On this page you can find all versions of the php package atomcoder/laravel-reorderable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-reorderable

Laravel Reorderable

Drag-and-drop sorting for Laravel Eloquent models, with both Blade and Livewire UI support.

What This Package Does

This package lets you:

If you have records like tasks, posts, sections, menu items, images, or lessons, this package gives you a clean way to let users reorder them.

Requirements

Installation

The install command publishes:

After installing, the usual setup is:

  1. add a sort column to your table
  2. add the trait to your model
  3. add your model to allowed_models
  4. load records using the ordered() scope
  5. render the Blade include or Livewire component

Quick Start

1. Add a sort column to your table

By default, the package uses a column named sort_order.

If you want a different column name such as position, that is fine. You will just need to tell the model which column to use.

2. Make your model reorderable

3. Allow the model in the package config

Edit config/reorderable.php:

If allowed_models is empty, the package accepts any Eloquent model that uses the trait. In most apps, whitelisting your models is safer and clearer.

4. Load the items in the correct order

Use ordered() whenever you fetch reorderable items for display.

To sort descending, pass a direction string or the enum:

SortDirection::fromValue() accepts SortDirection, asc or desc strings (case-insensitive), or null, and returns a SortDirection (defaults to Asc).

5. Render the UI

Blade:

Livewire:

That is all you need for a working reorderable list.

How It Works

When a user drags an item:

  1. the package reads the list order in the browser
  2. it sends the ordered item IDs to the package route
  3. the package updates the sort column in the database
  4. it dispatches an ItemsReordered event

For grouped lists, the reorder only applies inside the given group.

Model Setup Explained

Your model must:

HasSortOrder gives you

Model properties and methods

Item Required What it does
$sortColumn No Overrides the name of the database column that stores the order. If omitted, the package uses config('reorderable.sort_column').
$reorderSortDirection No Default direction for ordered() when no argument is provided. Accepts SortDirection or asc/desc strings (case-insensitive).
getReorderLabel() Usually yes Returns the text shown in the UI. The trait provides a fallback using name, title, label, or the primary key, but defining it explicitly is clearer.
getReorderKey() No Returns the identifier sent by the UI. The default is the model primary key. Keep this aligned with your actual primary key because reordering uses whereKey() internally.
ordered() No Query scope that sorts by the reorder column. Accepts SortDirection, asc/desc, or null (falls back to getDefaultSortDirection()).
getDefaultSortDirection() No Override to return a custom default direction as SortDirection (use SortDirection::fromValue() to normalize input).
moveToPosition() No Moves one model to a specific position and renumbers the rest.
reorderFromArray() No Reorders records based on an array of IDs. Used internally by the package.

Basic model example

Custom sort column example

Grouped Reordering

Grouped reordering is for cases where items should only reorder within a parent record.

Examples:

Example: reorder tasks inside one project

This means:

Auto-assigning sort order within a group on create

When a new model is created, the trait automatically sets the next sort value if the sort column is blank.

If you want that auto-assignment to happen inside a group, add this method to the model:

Now a newly created Task with project_id = 5 will get the next sort number inside project 5, not across all tasks.

Blade Usage

Render the Blade include anywhere you already have a collection of reorderable models.

Blade variables explained

Variable Required Type Meaning
items Yes iterable The models to display. These should already be loaded in the order you want shown, normally with ordered().
modelClass Yes string The fully qualified model class, for example App\Models\Task::class.
groupColumn No string or null The column used to limit reordering to a group, such as project_id.
groupValue No mixed The value of the group column, such as $project->id.
title No string Heading shown above the list. Default: Reorder Items.
listId No string DOM ID for the <ul>. Use a unique value if you render multiple lists on one page. Default: reorderable-list.

Blade layout requirements

The Blade view sends a fetch() request with a CSRF token and pushes its JavaScript into the scripts stack.

Your layout should include:

If your app does not render @stack('scripts'), the drag-and-drop JavaScript will not load.

Livewire Usage

Use the Livewire component when the list already lives inside a Livewire-driven screen.

Livewire props explained

Prop Required Type Meaning
:items Yes iterable The initial items to display.
model-class Yes string The model class to reorder.
group-column No string Group column such as project_id.
:group-value No mixed Group value such as $project->id.
title No string The card heading. Default: Reorder Items.
list-id No string Unique HTML ID for the list. Default: reorderable-livewire-list.

Livewire requirements

Make sure your page layout includes the normal Livewire directives:

Complete Example

Controller

Model

Blade view

Programmatic Reordering

You can reorder without the UI as well.

Move one item to a position

Move to a position inside a group:

Reorder from an array of IDs

Grouped:

Request Payload Sent by the UI

The Blade and Livewire UIs ultimately reorder using this shape:

The package route is:

If you change route_prefix in config, the URL changes with it.

Configuration

Published config file:

Config values explained

Key Default What it does
middleware ['web'] Middleware used on the reorder update route.
route_prefix 'reorderable' Prefix for package routes such as /reorderable/update and /reorderable/demo.
sort_column 'sort_order' Default sort column name used when the model does not define $sortColumn.
allowed_models [] Optional whitelist of models that may be reordered.
authorize null Optional callback that receives the current request and model class. Return true to allow the reorder.
demo.enabled false Turns the demo route on or off.
demo.middleware ['web'] Middleware applied to the demo route.

Authorization example

If the callback does not return true, the package aborts with 403.

Events

The package dispatches this event after a reorder succeeds:

Event properties:

Property Meaning
$modelClass The reordered model class.
$items The reordered IDs in their new order.
$groupColumn The group column used, if any.
$groupValue The group value used, if any.

Event listener example

Generator Command

The package includes a helper command:

This command:

It does not edit your model or config automatically. You still need to update the model and allowed_models yourself.

Generator options explained

Option Default Meaning
{name} none The model name, for example Task.
--table plural snake case of the model Table to alter, for example tasks.
--label title Model attribute that should be returned from getReorderLabel().
--column sort_order Sort column to create in the migration.

Demo Page

Enable the demo in config/reorderable.php:

Then visit:

If you changed route_prefix, the demo URL uses the new prefix.

Common Mistakes

Testing

License

MIT


All versions of laravel-reorderable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/support Version ^13.0
illuminate/routing Version ^13.0
illuminate/database Version ^13.0
illuminate/view Version ^13.0
livewire/livewire Version ^4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package atomcoder/laravel-reorderable contains the following files

Loading the files please wait ...