PHPackages                             james.xue/laravel-sortable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. james.xue/laravel-sortable

ActiveLibrary[Database &amp; ORM](/categories/database)

james.xue/laravel-sortable
==========================

Sortable behaviour for eloquent models

1.1.3(6y ago)210.1k↑150%2MITPHPPHP &gt;=7.0.0

Since May 11Pushed 6y agoCompare

[ Source](https://github.com/xiaoxuan6/laravel-sortable)[ Packagist](https://packagist.org/packages/james.xue/laravel-sortable)[ RSS](/packages/jamesxue-laravel-sortable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (6)Used By (2)

Sortable behaviour for Eloquent models
======================================

[](#sortable-behaviour-for-eloquent-models)

This package provides a trait that adds sortable behaviour to an Eloquent model.

The value of the order column of a new record of a model is determined by the maximum value of the order column of all records of that model + 1.

Installation
------------

[](#installation)

This package can be installed through Composer.

```
composer require james.xue/laravel-sortable

```

Usage
-----

[](#usage)

To add sortable behaviour to your model you must:

1. Use the trait `James\Sortable\SortableTrait;`;

    Use the trait `James\Sortable\Sortable`;
2. Optionally specify which column will be used as the order column. The default is `sort_field`.

### Example

[](#example)

```
use James\Sortable\SortableTrait;
use James\Sortable\Sortable;

class MyModel extends Eloquent implements Sortable
{

    use SortableTrait;

    public $sortable = [
        'sort_field' => 'view',
        'sort_when_creating' => true,
    ];

    ...
}
```

If you don't set a value `$sortable['sort_field']` the package will assume that your order column name will be named `sort_field`.

If you don't set a value `$sortable['sort_when_creating']` the package will automatically assign the highest order number to a new model;

Assuming that the db-table for `MyModel` is empty:

```
$myModel = new MyModel();
$myModel->save(); // sort_field for this record will be set to 1

$myModel = new MyModel();
$myModel->save(); // sort_field for this record will be set to 2

$myModel = new MyModel();
$myModel->save(); // sort_field for this record will be set to 3
```

You can also move a model:

```
$myModel = new MyModel();
$myModel->where('id', $id)->first()->move('up'); // up、down、top、end
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~15 days

Total

5

Last Release

2503d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2f8fdd2069c7594101452a5c802ae01209a31109d67a9299a67320752c30a1de?d=identicon)[xiaoxuan6](/maintainers/xiaoxuan6)

---

Top Contributors

[![xiaoxuan6](https://avatars.githubusercontent.com/u/32762220?v=4)](https://github.com/xiaoxuan6 "xiaoxuan6 (1 commits)")

---

Tags

laravelmodeleloquentsortablesortbehaviour

### Embed Badge

![Health badge](/badges/jamesxue-laravel-sortable/health.svg)

```
[![Health](https://phpackages.com/badges/jamesxue-laravel-sortable/health.svg)](https://phpackages.com/packages/jamesxue-laravel-sortable)
```

###  Alternatives

[spatie/eloquent-sortable

Sortable behaviour for eloquent models

1.5k22.9M268](/packages/spatie-eloquent-sortable)[jedrzej/pimpable

Laravel 4/5/6 package that allows to dynamically filter, sort and eager load relations for your models using request parameters

105179.0k1](/packages/jedrzej-pimpable)[rutorika/sortable

Adds sortable behavior and ordering to Laravel Eloquent models. Grouping and many to many supported.

299992.5k14](/packages/rutorika-sortable)[jedrzej/sortable

Sortable trait for Laravel's Eloquent models - sort your models using request parameters

54261.0k1](/packages/jedrzej-sortable)[akaunting/laravel-sortable

Sortable behavior package for Laravel

27175.6k](/packages/akaunting-laravel-sortable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
