PHPackages                             monurakkaya/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. monurakkaya/laravel-sortable

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

monurakkaya/laravel-sortable
============================

Enables simple sort for your Eloquent models

v1.0.1(4y ago)216MITPHPPHP ^7.4 || ^8.0

Since Feb 8Pushed 3y ago1 watchersCompare

[ Source](https://github.com/monurakkaya/laravel-sortable)[ Packagist](https://packagist.org/packages/monurakkaya/laravel-sortable)[ RSS](/packages/monurakkaya-laravel-sortable/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Laravel sortable
================

[](#laravel-sortable)

Enables simple sort for your Eloquent models

INSTALLATION
------------

[](#installation)

```
composer require monurakkaya/laravel-sortable

```

EXAMPLE
-------

[](#example)

```
$fooOne = Foo::create(['title' => 'Foo1', 'sort_order' => 1]);
$fooTwo = Foo::create(['title' => 'Foo2', 'sort_order' => 4]);
$fooThree = Foo::create(['title' => 'Foo3', 'sort_order' => 3]);

$records = Foo::get();
-Foo1
-Foo3
-Foo2

```

USAGE
-----

[](#usage)

### The model

[](#the-model)

Your model should use Monurakkaya\\Traits\\Sortable trait to enable auto sort;

```
use Monurakkaya\Sortable\Traits;

class Foo extends Model {
    use Sortable;
}

```

and that's all.

#### SETTINGS

[](#settings)

To change the column name to be sorted just override the `getSortableColumn` method on your model

```

class Foo extends Model {
    use Sortable;

    protected static function getSortableColumn()
    {
        return 'created_at';
    }
}

```

Default is `sort_order`

To change the sorting direction just override the `getSortableDirection` method on your model

```

class Foo extends Model {
    use Sortable;

    protected static function getSortableDirection()
    {
        return 'desc';
    }
}

```

Default is `asc`

### The schema

[](#the-schema)

\*\* You do not have to add new column, you can use existing columns like `created_at, id` etc to make your model able to auto-sort results.

#### To create the column

[](#to-create-the-column)

```
// This will generate an unsigned big integer column named `sort_order`
// which equivalent to $table->unsignedBigInteger('sort_order');
Schema::create('table', function (Blueprint $table) {
    ...
    $table->sortableColumn();
});

```

#### To drop the column

[](#to-drop-the-column)

```
Schema::table('table', function (Blueprint $table) {
    $table->dropSortableColumn();
});

```

#### To use your own column just pass the column name to override the default name

[](#to-use-your-own-column-just-pass-the-column-name-to-override-the-default-name)

```
// on create
$table->sortableColumn('my_column_name');

// on drop
$table->dropSortableColumn('my_column_name');

```

Using schema helper is optional. You can go on with your own definitions.

Tests
-----

[](#tests)

To run the tests, execute the following from the command line, while in the project root directory:

```
./vendor/bin/phpunit
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.1% 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 ~5 days

Total

2

Last Release

1548d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe63a20ff84ad0d46ff286893f0e77a1fc5c53961c6fcbe9df2748cf55a3aef6?d=identicon)[monurakkaya](/maintainers/monurakkaya)

---

Top Contributors

[![nbayramberdiyev](https://avatars.githubusercontent.com/u/23094428?v=4)](https://github.com/nbayramberdiyev "nbayramberdiyev (18 commits)")[![monurakkaya](https://avatars.githubusercontent.com/u/10274803?v=4)](https://github.com/monurakkaya "monurakkaya (11 commits)")

---

Tags

laravelmodeleloquentsortablesort

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/monurakkaya-laravel-sortable/health.svg)](https://phpackages.com/packages/monurakkaya-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)
