PHPackages                             gurgentil/laravel-eloquent-sequencer - 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. gurgentil/laravel-eloquent-sequencer

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

gurgentil/laravel-eloquent-sequencer
====================================

A package that allows you to create and manage sequences on Eloquent models

1.2.0(9mo ago)15248.6k↓81.4%14[2 issues](https://github.com/gurgentil/laravel-eloquent-sequencer/issues)[3 PRs](https://github.com/gurgentil/laravel-eloquent-sequencer/pulls)MITPHPPHP ^7.2.5|^8.0CI failing

Since Apr 27Pushed 9mo ago4 watchersCompare

[ Source](https://github.com/gurgentil/laravel-eloquent-sequencer)[ Packagist](https://packagist.org/packages/gurgentil/laravel-eloquent-sequencer)[ Docs](https://github.com/gurgentil/laravel-eloquent-sequencer)[ RSS](/packages/gurgentil-laravel-eloquent-sequencer/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (2)Versions (16)Used By (0)

Laravel Eloquent Sequencer
==========================

[](#laravel-eloquent-sequencer)

[![Latest Version](https://camo.githubusercontent.com/94426ba2343278006a8b79042d13b2f686f1e9c73da7d376728d430fb370057d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f67757267656e74696c2f6c61726176656c2d656c6f7175656e742d73657175656e6365722e7376673f7374796c653d666c61742d737175617265)](https://github.com/gurgentil/laravel-eloquent-sequencer/releases)[![GitHub Workflow Status](https://camo.githubusercontent.com/0015ffed9be3072a8e652375adb8e8b0a0cbb4e5722888de93480b8ed67e9e4d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f67757267656e74696c2f6c61726176656c2d656c6f7175656e742d73657175656e6365722f72756e2d74657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/0015ffed9be3072a8e652375adb8e8b0a0cbb4e5722888de93480b8ed67e9e4d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f67757267656e74696c2f6c61726176656c2d656c6f7175656e742d73657175656e6365722f72756e2d74657374733f6c6162656c3d7465737473)[![Quality Score](https://camo.githubusercontent.com/48371f710d9302b932e83db19270d5722486ebf4801162917b4484c7ba0eb696/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f67757267656e74696c2f6c61726176656c2d656c6f7175656e742d73657175656e6365722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/gurgentil/laravel-eloquent-sequencer)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

This package allows you to create and manage sequences for your Eloquent models.

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

[](#installation)

Install the package via composer:

```
composer require gurgentil/laravel-eloquent-sequencer
```

Configuration
-------------

[](#configuration)

To publish the configuration file run:

```
php artisan vendor:publish --provider="Gurgentil\LaravelEloquentSequencer\LaravelEloquentSequencerServiceProvider"
```

### Configuration parameters

[](#configuration-parameters)

You can change the default colum name, the initial value and the sequencing strategy in `config/eloquentsequencer.php`:

```
return [
    'column_name' => 'position',
    'initial_value' => 1,
    'strategy' => 'always',
];
```

The `strategy` configuration determines when sequencing should be triggered and accepts one of the following values: `always`, `on_create`, `on_update` or `never`.

### Model configuration

[](#model-configuration)

The `$sequenceable` attribute specifies the sequence column name for the model:

```
protected static $sequenceable = 'order';
```

The relationship key(s) that will group the sequence items together:

```
protected static $sequenceableKeys = [
    'task_list_id',
];
```

In the example above, a task list has many tasks.

For **polymorphic relationships** specify both relationship keys:

```
protected static $sequenceableKeys = [
    'commentable_id',
    'commentable_type',
];
```

Usage
-----

[](#usage)

In the example below, a task list may have many tasks.

```
use Gurgentil\LaravelEloquentSequencer\Traits\Sequenceable;
use Illuminate\Database\Eloquent\Model;

class Task extends Model
{
    use Sequenceable;

    protected $fillable = [
        'position',
    ];

    protected static $sequenceableKeys = [
        'task_list_id',
    ];

    public function taskList()
    {
        return $this->belongsTo(TaskList::class);
    }
}
```

### Create an object

[](#create-an-object)

```
Task::create([
    'position' => 1,
    'task_list_id' => 1,
]);
```

If no value is provided for the sequence attribute, the object will be placed at the end of the sequence.

```
Task::create(['task_list_id' => 1]);
```

### Update and delete objects

[](#update-and-delete-objects)

The other items in the sequence will be rearranged to keep the sequence consistent.

```
$task->update(['position' => 4]);
```

```
$task->delete();
```

### Get sequence value of an object

[](#get-sequence-value-of-an-object)

```
$value = $task->getSequenceValue();
```

### Get sequence column name

[](#get-sequence-column-name)

```
$columnName = Task::getSequenceColumnName();
```

### Disable automatic sequencing

[](#disable-automatic-sequencing)

```
$task->withoutSequencing()->update(['position' => 3]);
```

```
$task->withoutSequencing()->delete();
```

### Scope query to order results by sequence value

[](#scope-query-to-order-results-by-sequence-value)

```
$tasks = Task::sequenced()->get();
```

Artisan commands
----------------

[](#artisan-commands)

Assign sequence values to all records that have their values set to `null`.

```
php artisan sequence:populate \\App\\Task
```

Flush all sequence values for a model.

```
php artisan sequence:flush \\App\\Task
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

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

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Gustavo Rorato Gentil](https://github.com/gurgentil)
- [Michael Slowik](https://github.com/sl0wik)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance57

Moderate activity, may be stable

Popularity45

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 88.5% 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 ~145 days

Recently: every ~441 days

Total

15

Last Release

274d ago

Major Versions

0.2.0 → 1.0.02020-09-11

PHP version history (5 changes)0.0.1PHP ^7.1

0.0.2PHP ^7.2

1.0.0PHP ^7.3

1.0.4PHP ^7.2.5

1.0.5PHP ^7.2.5|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6fe26ccdc056dd1ae4c15a44e7799340501cc7a7e58d138b1fcb78b0034693e1?d=identicon)[gurgentil](/maintainers/gurgentil)

---

Top Contributors

[![gurgentil](https://avatars.githubusercontent.com/u/12678835?v=4)](https://github.com/gurgentil "gurgentil (54 commits)")[![riesjart](https://avatars.githubusercontent.com/u/23455176?v=4)](https://github.com/riesjart "riesjart (3 commits)")[![sl0wik](https://avatars.githubusercontent.com/u/2696038?v=4)](https://github.com/sl0wik "sl0wik (2 commits)")[![danielstgt](https://avatars.githubusercontent.com/u/13825655?v=4)](https://github.com/danielstgt "danielstgt (1 commits)")[![imanghafoori1](https://avatars.githubusercontent.com/u/6961695?v=4)](https://github.com/imanghafoori1 "imanghafoori1 (1 commits)")

---

Tags

laraveleloquentsequenceordersequenceable

### Embed Badge

![Health badge](/badges/gurgentil-laravel-eloquent-sequencer/health.svg)

```
[![Health](https://phpackages.com/badges/gurgentil-laravel-eloquent-sequencer/health.svg)](https://phpackages.com/packages/gurgentil-laravel-eloquent-sequencer)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.9M110](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k35.7M52](/packages/kirschbaum-development-eloquent-power-joins)[illuminate/database

The Illuminate Database package.

2.8k55.8M13.1k](/packages/illuminate-database)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.3M27](/packages/yajra-laravel-oci8)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121139.4k](/packages/highsolutions-eloquent-sequence)[rutorika/sortable

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

2891.1M18](/packages/rutorika-sortable)

PHPackages © 2026

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