PHPackages                             oddvalue/eloquent-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. oddvalue/eloquent-sortable

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

oddvalue/eloquent-sortable
==========================

Some additional features on top of https://github.com/spatie/eloquent-sortable

v2.2.0(3mo ago)2156.2k↓51%[1 PRs](https://github.com/oddvalue/eloquent-sortable/pulls)MITPHPPHP ^8.2CI passing

Since Jul 23Pushed 1w ago1 watchersCompare

[ Source](https://github.com/oddvalue/eloquent-sortable)[ Packagist](https://packagist.org/packages/oddvalue/eloquent-sortable)[ Docs](https://github.com/oddvalue/eloquent-sortable)[ RSS](/packages/oddvalue-eloquent-sortable/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (5)Dependencies (28)Versions (12)Used By (0)

[![](https://camo.githubusercontent.com/2bedf63f24cda7efab02da955dc11fb7ef8a060e2f26b73c33a7aac84529b8a3/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f737570706f72742d756b7261696e652e7376673f743d31)](https://supportukrainenow.org)

Some additional features on top of Spatie's [Eloquent Sortable](https://github.com/spatie/eloquent-sortable)
============================================================================================================

[](#some-additional-features-on-top-of-spaties-eloquent-sortable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2cfde54d94aef7f39b02460fd9e16bd9e0f45d8534cb4ee84b5925e9b7cdd5f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f646476616c75652f656c6f7175656e742d736f727461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oddvalue/eloquent-sortable)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0e0f66412dffd4833415c5354a8d6b8a8cdb1d3a561f3e2393e3276bd4f95153/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f646476616c75652f656c6f7175656e742d736f727461626c652f72756e2d74657374732e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/oddvalue/eloquent-sortable/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/c96fb8a0741734e1b042f600a16606570818424790730e7a69ac569b5f45528c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f646476616c75652f656c6f7175656e742d736f727461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oddvalue/eloquent-sortable)[![Coverage](https://camo.githubusercontent.com/09cdbc56e66271e5086795ef7ec1c71a46afed1d10cebcc5553fe6b61a159519/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f676973742e67697468756275736572636f6e74656e742e636f6d2f6f646476616c75652f39646438653530386362323433333732386434326132353831393337373065622f7261772f656c6f7175656e742d736f727461626c652d636f626572747572612d636f7665726167652e6a736f6e)](https://camo.githubusercontent.com/09cdbc56e66271e5086795ef7ec1c71a46afed1d10cebcc5553fe6b61a159519/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f676973742e67697468756275736572636f6e74656e742e636f6d2f6f646476616c75652f39646438653530386362323433333732386434326132353831393337373065622f7261772f656c6f7175656e742d736f727461626c652d636f626572747572612d636f7665726167652e6a736f6e)

This package is an extension of Spatie's excellent [Eloquent Sortable](https://github.com/spatie/eloquent-sortable). It adds the following additional features:

- New methods
    - `$model->moveBefore(int|Sortable $target): void`
    - `$model->moveAfter(int|Sortable $target): void`
    - `$model->moveBetween(int|Sortable $before = null, Sortable $after = null): void`
    - `$model->moveTo(int|Sortable $newPosition): void`

**Note:** The move methods rebuild the entire sequence so this package is not recommended for very large datasets.

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

[](#installation)

You can install the package via composer:

```
composer require oddvalue/eloquent-sortable
```

Usage
-----

[](#usage)

Implement the interface and use the trait.

```
class MyModel extends Model implements \Oddvalue\EloquentSortable\Sortable
{
    use \Oddvalue\EloquentSortable\SortableTrait;
}
```

```
# New model automatically sorted to the end of the list upon creation
$model = MyModel::create(['title' => 'foo']);

# Move the model before the 5th item in the list
$model->moveBefore(MyModel::where('order_column', 5)->first());
// OR
$model->moveBefore(5);

# Move the model after the 5th item in the list
$model->moveAfter(MyModel::where('order_column', 5)->first());
// OR
$model->moveAfter(5);

# Move the model between the 5th and 6th item in the list
$model->moveBetween(
    MyModel::where('order_column', 5)->first(),
    MyModel::where('order_column', 6)->first()
);
// OR
$model->moveBetween(5, 6);
# This is useful when using a javacript library that provides the node before
# and after the location an item is dropped

# Move the model to the 5th item in the list
$model->moveTo(MyModel::where('order_column', 5)->first());
// OR
$model->moveTo(5);
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/oddvalue/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [jim](https://github.com/oddvalue)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance91

Actively maintained with recent releases

Popularity36

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~336 days

Total

5

Last Release

93d ago

Major Versions

v1.0.1 → v2.0.02024-03-28

PHP version history (2 changes)v1.0.0PHP ^8.0

v2.2.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/8445ea4661367cd677e1c3caa05c7e4021f30ff5ca7978e9f436bc7fd7532bf5?d=identicon)[oddvalue](/maintainers/oddvalue)

---

Top Contributors

[![oddvalue](https://avatars.githubusercontent.com/u/10127404?v=4)](https://github.com/oddvalue "oddvalue (30 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (26 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (16 commits)")

---

Tags

laraveleloquent-sortableoddvalue

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/oddvalue-eloquent-sortable/health.svg)

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

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M99](/packages/dedoc-scramble)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k38](/packages/spatie-laravel-passkeys)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

213389.8k2](/packages/wnx-laravel-backup-restore)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17558.6k](/packages/lacodix-laravel-model-filter)

PHPackages © 2026

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