PHPackages                             bradietilley/laravel-snowflake - 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. bradietilley/laravel-snowflake

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

bradietilley/laravel-snowflake
==============================

Laravel implementation for Snowflake IDs

v1.1.0(1y ago)2143[1 issues](https://github.com/bradietilley/laravel-snowflake/issues)MITPHPPHP ^8.4

Since Feb 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bradietilley/laravel-snowflake)[ Packagist](https://packagist.org/packages/bradietilley/laravel-snowflake)[ RSS](/packages/bradietilley-laravel-snowflake/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (7)Versions (5)Used By (0)

Laravel Snowflake
=================

[](#laravel-snowflake)

A Laravel wrapper of [PHP Snowflake](https://github.com/bradietilley/php-snowflake) to provide a simple, opinionated implementation of Snowflake IDs for your eloquent models.

[![Static Analysis](https://github.com/bradietilley/laravel-snowflake/actions/workflows/static.yml/badge.svg)](https://github.com/bradietilley/laravel-snowflake/actions/workflows/static.yml/badge.svg)[![Tests](https://github.com/bradietilley/laravel-snowflake/actions/workflows/tests.yml/badge.svg)](https://github.com/bradietilley/laravel-snowflake/actions/workflows/tests.yml/badge.svg)[![Laravel Version](https://camo.githubusercontent.com/1a0dd3f2234cab82fce80f256db4918d50a06680a4984f5db9f1ca7f58a1daea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c25323056657273696f6e2d31312e782d463933323243)](https://camo.githubusercontent.com/1a0dd3f2234cab82fce80f256db4918d50a06680a4984f5db9f1ca7f58a1daea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c25323056657273696f6e2d31312e782d463933323243)[![PHP Version](https://camo.githubusercontent.com/8a0a221dc39a103ef0e073c685a966c64219dba011234d99187a76a68be4a7fd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50485025323056657273696f6e2d254532253839254135382e342d344635423933)](https://camo.githubusercontent.com/8a0a221dc39a103ef0e073c685a966c64219dba011234d99187a76a68be4a7fd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50485025323056657273696f6e2d254532253839254135382e342d344635423933)

Introduction
------------

[](#introduction)

The laravel-snowflake package provides a seamless way to generate unique, time-ordered, distributed IDs within your Laravel application. Unlike traditional auto-incrementing IDs, Snowflake IDs offer several advantages: they eliminate ID collisions across distributed systems, enhance horizontal scalability, and prevent predictable sequential exposure of database records. Compared to UUIDs and ULIDs, Snowflake IDs are shorter, visually appealing, and easier to write out, making them ideal for public identifiers. This package integrates smoothly with Laravel, offering microsecond precision while ensuring high-performance, conflict-free ID generation across multiple clusters and workers. 🚀

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

[](#installation)

```
composer require bradietilley/laravel-snowflake

```

Documentation
-------------

[](#documentation)

**Preparing your schema:**

You'll want to make sure that your model's primary key does not autoincrement. Autoincrement is automatically added when you use `$table->id();` so go ahead and switch this out:

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

**Integrating with you models:**

Next you'll want to add the `HasSnowflake` trait to your models. This trait this will handle all aspects of a snowflake ID including:

- Automatically setting the `id` to a Snowflake ID
- Configuring the cast for `id` to `string`
- Disabling `increments` on the model
- Configuring the `keyType` to `string`

This can be done as simple as:

```
use BradieTilley\Snowflakes\Eloquent\HasSnowflake;

class SomeModel extends Model
{
    use HasSnowflake;
}
```

You're all set.

```
$model = SomeModel::create();
$model->id; // 9348975348573485734
```

### Concurrency

[](#concurrency)

The package includes a `LaravelSequenceResolver` for PHP Snowflake, which utilizes a cache repository to manage the generation of multiple concurrent IDs within the same microsecond.

You can configure various cache-related options, such as:

- The cache store (`snowflakes.sequencing.store`)
- Cache prefix (`snowflakes.sequencing.prefix`)
- Cache lock expiry (`snowflakes.sequencing.expiry`)
- Cache lock wait time (`snowflakes.sequencing.wait`)

These settings allow for proper handling of concurrent ID generation in distributed environments.

### Testing

[](#testing)

In unit testing scenarios, you may want to generate sequential, predictable IDs, similar to traditional auto-incrementing IDs.

By enabling the `snowflakes.testing` configuration setting, the standard `SnowflakeIdentifierResolver` is automatically swapped with a `SequentialIdentifierResolver`. This generates IDs that are realistic in length and follow a standard auto-incrementing pattern.

When in testing mode, Snowflake IDs can be grouped using the `$group` argument in the `BradieTilley\Snowflakes\SnowflakeGenerator::make()->id($group)` or `BradieTilley\Snowflake\Snowflake::id($group)` methods. The `$group` is automatically set to the respective model class name.

For example, both `Product::create()` and `User::create()` generate an ID of `9000000000000000001`, then `9000000000000000002`, then `9000000000000000003` and so-on.

Author
------

[](#author)

- [Bradie Tilley](https://github.com/bradietilley)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

Total

4

Last Release

465d ago

### Community

Maintainers

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

---

Top Contributors

[![bradietilley](https://avatars.githubusercontent.com/u/44430471?v=4)](https://github.com/bradietilley "bradietilley (12 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bradietilley-laravel-snowflake/health.svg)

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

###  Alternatives

[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

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