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

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

tonylaurent/laravel-eloquent-sequencer
======================================

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

01.1kPHP

Since Aug 8Pushed 3y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#laravel-eloquent-sequencer)

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

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

[](#installation)

Install the package via composer:

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

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

[](#configuration)

To publish the configuration file run:

```
php artisan vendor:publish --provider="TonyLaurent\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 TonyLaurent\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

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor1

Top contributor holds 88.3% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b62f52197e1bcdb652f58f93bb83966ecd465b06c81a974f722965550ce3968?d=identicon)[tonylaurent](/maintainers/tonylaurent)

---

Top Contributors

[![gurgentil](https://avatars.githubusercontent.com/u/12678835?v=4)](https://github.com/gurgentil "gurgentil (53 commits)")[![riesjart](https://avatars.githubusercontent.com/u/23455176?v=4)](https://github.com/riesjart "riesjart (3 commits)")[![tonylaurent](https://avatars.githubusercontent.com/u/6961694?v=4)](https://github.com/tonylaurent "tonylaurent (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)")

### Embed Badge

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

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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