PHPackages                             adamthehutt/laravel-unique-bigint-ids - 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. adamthehutt/laravel-unique-bigint-ids

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

adamthehutt/laravel-unique-bigint-ids
=====================================

This allows for the generation of sequential IDs that can be created before inserting into the database and are virtually (but not totally) guaranteed to be globally unique for the app. Additional benefits come from generating IDs before DB persistence, which streamlines code for, e.g., attaching related records.

v0.7.1(5y ago)31.7k[2 PRs](https://github.com/adamthehutt/laravel-unique-bigint-ids/pulls)1MITPHPPHP &gt;=7.3

Since Jun 12Pushed 4y agoCompare

[ Source](https://github.com/adamthehutt/laravel-unique-bigint-ids)[ Packagist](https://packagist.org/packages/adamthehutt/laravel-unique-bigint-ids)[ RSS](/packages/adamthehutt-laravel-unique-bigint-ids/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (6)Versions (20)Used By (1)

Laravel Unique 64-bit Integer IDs
---------------------------------

[](#laravel-unique-64-bit-integer-ids)

This allows for the generation of sequential IDs that can be created before inserting into the database and are virtually (but not totally) guaranteed to be globally unique for the app.

### Installation

[](#installation)

Install using composer:

```
composer require adamthehutt/laravel-unique-bigint-ids
```

Then publish the configuration:

```
php artisan vendor:publish
```

To use this package with a model, just use the contract and the trait:

```
use AdamTheHutt\LaravelUniqueBigintIds\Contracts\IdGenerator;
use AdamTheHutt\LaravelUniqueBigintIds\GeneratesIdsTrait;

class MyModel extends Model implements IdGenerator
{
    use GeneratesIdsTrait;
```

### DB Migrations

[](#db-migrations)

If you are going to use the trait with existing models, then you'll need to create and run migrations to make sure the relevant primary and foreign keys are all unsigned 64-bit integers without auto-increment, e.g.,

```
$table->bigInteger("id")->unsigned()->primary();
$table->bigInteger("foreign_id")->unsigned();
```

### What's wrong with UUIDs?

[](#whats-wrong-with-uuids)

Nothing! UUIDs are great and I use them all the time. But they solve a different category of problems and come with non-trivial challenges when used as primary keys. The IDs generated by this package are plain old integers (albeit very large ones). They are *not* globally unique like UUIDs. But they are virtually guaranteed to be unique within the scope of your Laravel application.

### What's wrong with AUTO\_INCREMENT?

[](#whats-wrong-with-auto_increment)

Conventional, auto-incremented primary keys are fine if that's your cup of tea. But there are practical benefits from generating an ID in the application upon model creation, rather than waiting until it has been persisted in the database.

##### Better handling of complex relations

[](#better-handling-of-complex-relations)

Complex real-world entities often need multiple related eloquent models to be fully represented. This can be awkward with standard auto-incremented IDs since you can't properly associate or attach related models until after the "main" one has been saved to the database. When IDs are assigned on model creation, you can fully associate all related models as they are built and then safely save them to the database without worrying about "last second" assignment of foreign keys.

##### Fear not sharded databases

[](#fear-not-sharded-databases)

If your application uses database shards you don't need to worry about different databases duplicating each other's primary keys.

##### One fewer roundtrip

[](#one-fewer-roundtrip)

There's a tiny performance boost from avoiding the additional roundtrip to the database that comes from calling LAST\_INSERT\_ID().

### Configuration / Strategies

[](#configuration--strategies)

The package provides multiple methods for generating the IDs:

- "timestamp" - The default method is to use the 16 digits of a microsecond timestamp and append the last 2 digits of the current process ID. This should work 99.9% of the time.
- "uuid\_short" - You can edit the config file to set "uuid\_short" as the generation strategy. This will call the UUID\_SHORT() mysql function in your database and use the returned value.
- "redis" - You can edit the config file to set "redis" as the generation strategy. In this case, the Laravel Redis facade will be used to increment and retrieve an incremented ID. If the key is not present, it will be initialized using the timestamp strategy.

### Javascript Gotchas

[](#javascript-gotchas)

Javascript barfs on integers larger than 2^53. When serializing models to JSON it's therefore important to cast large 64-bit integers to strings. This package handles that for you, but that only affects the models that use it. If you have other models that don't use this package's trait but have foreign key relationships with those that do, then you'll need to address this when serializing them to JSON.

Alternatively, you can set the `UNIQUE_BIGINT_ID_JAVASCRIPT_SAFE` environment variable to true. This will cause the library to use slightly reduced precision when generating timestamp-based IDs: 14 significant digits instead of 16. This should not increase the likelihood of collisions, but could result in a very slight performance hit, since it becomes impossible to generate more than 2 IDs in the same 1/10000th of second.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

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

###  Release Activity

Cadence

Every ~40 days

Recently: every ~35 days

Total

16

Last Release

1915d ago

PHP version history (2 changes)v0.1-beta.1PHP &gt;=7.3

v0.3.0PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/57567?v=4)[Adam Huttler](/maintainers/adamthehutt)[@adamthehutt](https://github.com/adamthehutt)

---

Top Contributors

[![adamthehutt](https://avatars.githubusercontent.com/u/57567?v=4)](https://github.com/adamthehutt "adamthehutt (25 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![davidwyly](https://avatars.githubusercontent.com/u/13552783?v=4)](https://github.com/davidwyly "davidwyly (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/adamthehutt-laravel-unique-bigint-ids/health.svg)

```
[![Health](https://phpackages.com/badges/adamthehutt-laravel-unique-bigint-ids/health.svg)](https://phpackages.com/packages/adamthehutt-laravel-unique-bigint-ids)
```

###  Alternatives

[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[aglipanci/laravel-eloquent-case

Adds CASE statement support to Laravel Query Builder.

115157.2k](/packages/aglipanci-laravel-eloquent-case)

PHPackages © 2026

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