PHPackages                             firevel/model-random-id - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. firevel/model-random-id

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

firevel/model-random-id
=======================

Model random ID generator for Laravel.

0.0.3(3y ago)19.4k↓50%MITPHP

Since Oct 14Pushed 1y agoCompare

[ Source](https://github.com/firevel/model-random-id)[ Packagist](https://packagist.org/packages/firevel/model-random-id)[ RSS](/packages/firevel-model-random-id/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

Model Random ID Generator for Laravel
=====================================

[](#model-random-id-generator-for-laravel)

A package for generating random `BIGINT` IDs as primary keys in Laravel models. These IDs are compatible with MySQL `BIGINT` columns and JavaScript's `MAX_SAFE_INTEGER`.

### Purpose

[](#purpose)

Systems using distributed databases like [Cloud Spanner](https://cloud.google.com/spanner) or [Firestore](https://cloud.google.com/firestore) shouldn't use incremental id's to avoid bottlenecks. [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier) can be used as an alternative but long strings can cause performance issues and UX issues. Random BIGINT is a middle ground between incremental id and UUID.

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

[](#installation)

Install the package via Composer:

```
composer require firevel/model-random-id
```

Usage
-----

[](#usage)

### Database Setup

[](#database-setup)

Ensure your database table uses a `BIGINT` primary key. For example:

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

### Model Setup

[](#model-setup)

Add the trait to your model:

```
use \Firevel\ModelRandomId\HasRandomId;
```

Disable auto-incrementing for the primary key:

```
/**
 * Indicates if the IDs are auto-incrementing.
 *
 * @var bool
 */
public $incrementing = false;
```

Limitations
-----------

[](#limitations)

While random number generation reduces the risk of ID collisions, it is not entirely immune to conflicts. The more IDs you generate, the higher the chance of a collision due to the Birthday Paradox—where random sampling within a finite range (in this case, BIGINT) increases the likelihood of overlap as the number of samples grows. For use cases involving millions of rows or extremely high throughput, consider pre-generating a list of unique IDs and distributing them to avoid runtime conflicts. This approach ensures scalability while preserving randomness.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

Every ~292 days

Total

3

Last Release

1459d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ef4a79c6f9a9afe04267a19b98fe0a5a45930c92d08fd720b233ab21ae102ca?d=identicon)[sl0wik](/maintainers/sl0wik)

---

Top Contributors

[![sl0wik](https://avatars.githubusercontent.com/u/2696038?v=4)](https://github.com/sl0wik "sl0wik (15 commits)")

---

Tags

randomlaraveluuidfirevel

### Embed Badge

![Health badge](/badges/firevel-model-random-id/health.svg)

```
[![Health](https://phpackages.com/badges/firevel-model-random-id/health.svg)](https://phpackages.com/packages/firevel-model-random-id)
```

###  Alternatives

[webpatser/laravel-uuid

Laravel integration for webpatser/uuid - High-performance drop-in UUID replacements (15% faster than Ramsey). Provides Str macros, HasUuids trait, facades, and casts. RFC 4122/9562 compliant.

1.8k17.3M129](/packages/webpatser-laravel-uuid)[skywarth/chaotic-schedule

Randomize scheduled command execution time and date intervals

12142.3k](/packages/skywarth-chaotic-schedule)[madewithlove/laravel-nova-uuid-support

Adds uuid and other string identifier support to Laravel Nova

28132.9k](/packages/madewithlove-laravel-nova-uuid-support)[riipandi/laravel-optikey

Use UUID, Ulid, or nanoid as optional or primary key in Laravel.

429.1k](/packages/riipandi-laravel-optikey)[sinergi/token

PHP library to generate random strings

188.7k9](/packages/sinergi-token)

PHPackages © 2026

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