PHPackages                             rorecek/laravel-autoincrement - 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. rorecek/laravel-autoincrement

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

rorecek/laravel-autoincrement
=============================

Set table AUTO\_INCREMENT values in your Laravel application

v1.0.4(2y ago)122252MITPHPPHP ^7.1|^8.0

Since Aug 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/rorecek/laravel-autoincrement)[ Packagist](https://packagist.org/packages/rorecek/laravel-autoincrement)[ Docs](https://github.com/rorecek/laravel-autoincrement)[ RSS](/packages/rorecek-laravel-autoincrement/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

Laravel AutoIncrement
=====================

[](#laravel-autoincrement)

This package will help you set table AUTO\_INCREMENT values in your Laravel application.

### Why do you need to change auto-increment values?

[](#why-do-you-need-to-change-auto-increment-values)

If you do not change auto-increment values of your tables you are exposing how many records you have in there. Imagine some user makes an order and is redirected to this order detail URL `https://example.com/orders/10`. User will know then that there are only 10 orders in the whole system which is probably information you do not want to share. If you will change your table to start with a higher auto-increment number, for example, 512322, it will not be that obvious (`https://example.com/orders/512332`).

But what if he makes another order month from now? There will be only small difference between these numbers and anyone can easily calculate your monthly activity. There is an easy solution for this. Add auto-increment update toLaravel's command scheduler and add some random number to your next auto-increment id automatically on hourly, daily, monthly, etc., basis.

### What are the benefits?

[](#what-are-the-benefits)

- Integer values are way more efficient than UUIDs or other types of string ids
- Sorting by id still leads to chronological order
- You do not expose the total number of resources in your database, for example `https://example.com/users/10`

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

[](#installation)

You can install this package via composer using this command:

```
 composer require rorecek/laravel-autoincrement
```

Usage
-----

[](#usage)

You can use this package to set the next auto-increment id to a specific value, or to add a number to current value or to reset auto-increment to the lowest possible value.

```
AutoIncrement::table('items')->set(100);
// Set table auto-increment value to 100

AutoIncrement::table('items')->add(500);
// Increase current auto-increment value by 500

AutoIncrement::table('items')->addRandomBetween(10, 100);
// Increase current auto-increment value by random number between 10 and 100

AutoIncrement::table('items')->reset();
// Reset auto-increment to the lowest value possible taking existing records in consideration.
```

### Migrations

[](#migrations)

Set auto-increments directly in your migrations.

```
Schema::create('items', function (Blueprint $table) {
  $table->bigIncrements('id');
  $table->timestamps();
});

AutoIncrement::table('items')->set(101);
// Next auto-increment id will be 101
```

### Scheduler

[](#scheduler)

Setup automatic auto-increment increases using task scheduler.

```
// App\Console\Kernel.php

protected function schedule(Schedule $schedule)
{
    $schedule->call(function () {
        AutoIncrement::table('messages')->add(35);
    })->hourly();

    $schedule->call(function () {
        AutoIncrement::table('registrations')->addRandomBetween(10, 100);
        AutoIncrement::table('bookings')->addRandomBetween(100, 500);
    })->daily();
}
```

Advanced usage
--------------

[](#advanced-usage)

You can optionally use different connections and/or closures if needed.

```
AutoIncrement::connection('foo')->table('items')->...
// Using different connection

AutoIncrement::table('items')->set(function () {
    return (int) date('ymd') . 1001;
});
// Using closure
```

Support
-------

[](#support)

If you believe you have found an issue, please report it using the [GitHub issue tracker](https://github.com/rorecek/laravel-ulid/issues), or better yet, fork the repository and submit a pull request.

If you're using this package, I'd love to hear your thoughts. Thanks!

License
-------

[](#license)

The MIT License (MIT). [Pavel Rorecek](https://laravelist.com)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity67

Established project with proven stability

 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

Every ~348 days

Total

5

Last Release

1054d ago

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

v1.0.4PHP ^7.1|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a075f7a729bd9caee248c2417be49bddebd3f4abf44ae1d5573625e0bcccf314?d=identicon)[rorecek](/maintainers/rorecek)

---

Top Contributors

[![rorecek](https://avatars.githubusercontent.com/u/6564004?v=4)](https://github.com/rorecek "rorecek (5 commits)")

---

Tags

laravelmysqlidautoincrementauto-increment

### Embed Badge

![Health badge](/badges/rorecek-laravel-autoincrement/health.svg)

```
[![Health](https://phpackages.com/badges/rorecek-laravel-autoincrement/health.svg)](https://phpackages.com/packages/rorecek-laravel-autoincrement)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[poing/earmark

Laravel package to generate values in a unique and customizable series.

10712.9k](/packages/poing-earmark)[itelmenko/laravel-mysql-logger

Laravel MySQL driver for Monolog

21141.9k](/packages/itelmenko-laravel-mysql-logger)[addapp/laravel-query-log

Logs full mysql queries.

135.4k](/packages/addapp-laravel-query-log)[ramadan/easy-model

A Laravel package for enjoyably managing database queries.

101.6k](/packages/ramadan-easy-model)

PHPackages © 2026

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