PHPackages                             m165437/eloquent-numbered - 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. m165437/eloquent-numbered

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

m165437/eloquent-numbered
=========================

Sequentially numbers your Eloquent model instances

v1.0.0(7y ago)08MITPHPPHP &gt;=7.0

Since Aug 21Pushed 7y ago1 watchersCompare

[ Source](https://github.com/M165437/eloquent-numbered)[ Packagist](https://packagist.org/packages/m165437/eloquent-numbered)[ Docs](https://github.com/m165437/eloquent-numbered)[ RSS](/packages/m165437-eloquent-numbered/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Numbered Eloquent Models
========================

[](#numbered-eloquent-models)

[![GitHub release](https://camo.githubusercontent.com/8a7f26d32d64e29bb20ff275688adf6db1f899692c9725f0e2a401a2cab19186/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f4d3136353433372f656c6f7175656e742d6e756d62657265642e737667)](https://github.com/M165437/eloquent-numbered/releases/latest)[![Unstable](https://camo.githubusercontent.com/3e799c60bd3e816e4f97b00f6f279f0a040184b98a78275eedc6c30b41cb20ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f756e737461626c652d6d61737465722d6f72616e67652e737667)](https://github.com/M165437/eloquent-numbered/tree/master)[![License](https://camo.githubusercontent.com/008c1bd747b7c6ddd006ac0893f6dc9d09b2038ddc512eb3e157d39587dcfea8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666c617426636f6c6f72423d343538393739)](https://github.com/M165437/eloquent-numbered/blob/master/LICENSE.md)[![Twitter](https://camo.githubusercontent.com/235cc6cff5a92f58abb485840a86e5a3e19ebb8c89729fbb1b9b0b10b5a9e53b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f747769747465722d404d3136353433372d626c75652e7376673f7374796c653d666c617426636f6c6f72423d303061636564)](http://twitter.com/M165437)

This package sequentially numbers your Eloquent model instances, constrained by a [scope](https://laravel.com/docs/master/eloquent#local-scopes) `numbered` that you customize.

On every `created`, `deleted`, `updated` and `restored` event, the models in the scope get renumbered.

When the numbering happens, the model that raised the event is injected into the method and can be used to further limit the scope.

Retrieved models will include a `number` attribute (customizable).

What is this good for? Rankings, positioning, row numbers, the fifth of something – when calculating the number ”on-the-fly“ is not an option.

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

[](#installation)

Install the package via composer:

```
composer require m165437/eloquent-numbered
```

Usage
-----

[](#usage)

Add the trait `M165437\EloquentNumbered\Numbered` to your model:

```
use Illuminate\Database\Eloquent\Model;
use M165437\EloquentNumbered\Numbered;

class MyModel extends Model
{
    use Numbered;
    ...
}
```

Add a `number` field to your model migration:

```
Schema::create('my_model', function (Blueprint $table) {
    $table->integer('number')->nullable();
    ...
});
```

If you would like to name this field / attribute differently, set the constant `NUMBER` on the model accordingly, e.g.

```
const NUMBER = 'rank';
```

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

[](#configuration)

The default numbering scope (included with the trait) sorts the model instances by date in ascending order:

```
public function scopeNumbered($query, $model = null)
{
    return $query->oldest();
}
```

If you want to customize the scope, add it to your model.

When the numbering happens, the model that raised the event is injected into the method and can be used to further limit the scope, e.g. numbering the model instances for each user individually:

```
public function scopeNumbered($query, $model = null)
{
    return $query->oldest()
        ->when($model, function ($query, $model) {
            return $query->where('user_id', $model->user_id)
        });
}
```

Tests
-----

[](#tests)

The package contains some integration/smoke tests, set up with Orchestra. The tests can be run via phpunit.

```
vendor/bin/phpunit
```

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

[](#contributing)

Thank you for considering contributing to this package! Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

License
-------

[](#license)

This package is licensed under the MIT License (MIT). Please see the [LICENSE](LICENSE.md) file for more information.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Unknown

Total

1

Last Release

2818d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/48c2aae37faeffc2b5ecbf9257009482fc87c5c56744d60e8f165a56f08e90f3?d=identicon)[m165437](/maintainers/m165437)

---

Top Contributors

[![M165437](https://avatars.githubusercontent.com/u/711773?v=4)](https://github.com/M165437 "M165437 (3 commits)")

---

Tags

laravelmodeleloquentrankingnumberednumberingranked

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/m165437-eloquent-numbered/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M70](/packages/mongodb-laravel-mongodb)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[sebastiaanluca/laravel-boolean-dates

Automatically convert Eloquent model boolean attributes to dates (and back).

40111.7k1](/packages/sebastiaanluca-laravel-boolean-dates)

PHPackages © 2026

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