PHPackages                             bytestgear/eloquent-incrementable - 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. bytestgear/eloquent-incrementable

Abandoned → [testmonitor/eloquent-incrementable](/?search=testmonitor%2Feloquent-incrementable)Library[Database &amp; ORM](/categories/database)

bytestgear/eloquent-incrementable
=================================

Define a custom auto-increment field in your Eloquent model, that is determined through PHP rather than your database engine.

7.0.0(1y ago)77493[1 PRs](https://github.com/testmonitor/eloquent-incrementable/pulls)MITPHPPHP ^8.2CI failing

Since May 4Pushed 6mo ago3 watchersCompare

[ Source](https://github.com/testmonitor/eloquent-incrementable)[ Packagist](https://packagist.org/packages/bytestgear/eloquent-incrementable)[ RSS](/packages/bytestgear-eloquent-incrementable/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (9)Dependencies (7)Versions (11)Used By (0)

Incrementable Eloquent models
=============================

[](#incrementable-eloquent-models)

[![Latest Stable Version](https://camo.githubusercontent.com/26493ffc713db94c215ef50eedc697c6ba58b8abf4f7e99645eacb4a687f039b/68747470733a2f2f706f7365722e707567782e6f72672f746573746d6f6e69746f722f656c6f7175656e742d696e6372656d656e7461626c652f762f737461626c65)](https://packagist.org/packages/testmonitor/eloquent-incrementable)[![StyleCI](https://camo.githubusercontent.com/0dffa1904b2a5ff7c3dc99f7b9d0302aa30a8c4e00f7bc814a2a552e52a1c844/68747470733a2f2f7374796c6563692e696f2f7265706f732f38393538363036362f736869656c64)](https://styleci.io/repos/89586066)[![codecov](https://camo.githubusercontent.com/baa22bcc7ad4aba29d61a5ef8db22478726026b264b9ef9e912a8c7eec991571/68747470733a2f2f636f6465636f762e696f2f67682f746573746d6f6e69746f722f656c6f7175656e742d696e6372656d656e7461626c652f67726170682f62616467652e7376673f746f6b656e3d4455334e535a5631384f)](https://codecov.io/gh/testmonitor/eloquent-incrementable)[![License](https://camo.githubusercontent.com/00bd57d8fb38d6bf21c4ee1b4dccfb816b7f7d3ecc1786e0612534ae078e41eb/68747470733a2f2f706f7365722e707567782e6f72672f746573746d6f6e69746f722f656c6f7175656e742d696e6372656d656e7461626c652f6c6963656e7365)](https://packagist.org/packages/eloquent-incrementable)

Define a custom auto-increment field in your Eloquent model, that is determined through PHP rather than your database engine.

Furthermore, by making use of increment groups, you can restart counting in-table based on other fields. Consider this example:

id**code**project\_id1**1**12**2**13**3**14**1**25**2**2Imagine a bug tracking application that stores each bug in a single table, but is represented on a per-project basis. You'll want start each project with a fresh bug count, while maintaining a unique database id. Incrementable will enable you to automatically reset the `code` counter once a new `project_id` is defined.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)
- [Tests](#tests)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

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

[](#installation)

This package can be installed through Composer:

```
$ composer require testmonitor/eloquent-incrementable
```

Usage
-----

[](#usage)

In order to add Incrementable to your Eloquent model, you'll need to:

1. Use the trait `TestMonitor\Incrementable\Traits\Incrementable` on your model(s).
2. Configure the incrementable field *(note: make sure its an integer column)*.
3. Optionally, add one or more increment groups.

Add the Incrementable trait on the models you want to track:

```
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use TestMonitor\Incrementable\Traits\Incrementable;

class Bug extends Model
{
    use Incrementable, SoftDeletes;

    protected $table = 'bugs';

    protected $incrementable = 'code';

    // This will cause the code to reset once
    // a new project_id is found.
    protected $incrementableGroup = ['project_id'];
}
```

In order to avoid collisions, Incrementable will preserve the count for a soft-deleted model. Although this will cause a gap between this and the next model, it will ensure uniqueness when the model is restored.

Examples
--------

[](#examples)

In this example, we have set up the following:

- A table containing a `name` and `code` field.
- An Eloquent model called `App\Bug`, which uses the Incrementable trait
- A property on the Bug model: `$incrementable = 'code'`

We can now run this example:

```
$bug = new App\Bug(['name' => 'It doesn\'t work.']);
$bug->save();

// Will show '1'
echo $bug->code;

$bug = new App\Bug(['name' => 'It really doesn\'t work.']);
$bug->save();

// Will show '2'
echo $bug->code;
```

Tests
-----

[](#tests)

The package contains integration tests. You can run them using PHPUnit.

```
$ vendor/bin/phpunit

```

Changelog
---------

[](#changelog)

Refer to [CHANGELOG](CHANGELOG.md) for more information.

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

[](#contributing)

Refer to [CONTRIBUTING](CONTRIBUTING.md) for contributing details.

Credits
-------

[](#credits)

- [Thijs Kok](https://www.testmonitor.com/)
- [Stephan Grootveld](https://www.testmonitor.com/)
- [Frank Keulen](https://www.testmonitor.com/)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Refer to the [License](LICENSE.md) for more information.

###  Health Score

48

↑

FairBetter than 94% of packages

Maintenance58

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

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

Recently: every ~388 days

Total

9

Last Release

400d ago

Major Versions

2.2.0 → 3.0.02021-01-07

3.0.0 → 4.0.02022-04-04

4.0.0 → 5.0.02023-04-09

5.0.0 → 6.0.02024-11-27

6.0.0 → 7.0.02025-04-09

PHP version history (6 changes)1.0.0PHP ^7.0

2.1.0PHP ^7.2

3.0.0PHP ^7.4|^8.0

4.0.0PHP ^8.0

5.0.0PHP ^8.1

6.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/47f66133b6b4806a16aaed043daa733f5e97adb7a10c9982d01a1cda9f492040?d=identicon)[stefanius](/maintainers/stefanius)

![](https://www.gravatar.com/avatar/39f48c881813b7d3b044ca5660aa5ab9e60b5dd7c34ed4a47acbb11bd20b7593?d=identicon)[thijskok](/maintainers/thijskok)

---

Top Contributors

[![stefanius](https://avatars.githubusercontent.com/u/2707905?v=4)](https://github.com/stefanius "stefanius (39 commits)")[![thijskok](https://avatars.githubusercontent.com/u/1344550?v=4)](https://github.com/thijskok "thijskok (38 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")

---

Tags

counteloquentincrementlaravelmodellaravelmodeleloquentcountincrementtestmonitor

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/bytestgear-eloquent-incrementable/health.svg)

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

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

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

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[cviebrock/eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel

4.0k13.6M253](/packages/cviebrock-eloquent-sluggable)[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[spiritix/lada-cache

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

591444.8k2](/packages/spiritix-lada-cache)

PHPackages © 2026

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