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

ActiveLibrary

cmariesprp/laravel-snowflake
============================

Laravel implementation for Snowflake IDs

1251[1 issues](https://github.com/cmariesprp/laravel-snowflake/issues)[1 PRs](https://github.com/cmariesprp/laravel-snowflake/pulls)PHP

Since Apr 16Pushed 1y agoCompare

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

READMEChangelogDependenciesVersions (1)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

13

—

LowBetter than 1% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

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

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

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

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

PHPackages © 2026

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