Download the PHP package bradietilley/laravel-snowflake without Composer

On this page you can find all versions of the php package bradietilley/laravel-snowflake. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-snowflake

Laravel Snowflake

A Laravel wrapper of PHP Snowflake to provide a simple, opinionated implementation of Snowflake IDs for your eloquent models.

Static Analysis Tests Laravel Version PHP Version

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

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:

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:

This can be done as simple as:

You're all set.

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:

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

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


All versions of laravel-snowflake with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
laravel/framework Version ^11.40
spatie/laravel-package-tools Version ^1.16
bradietilley/php-snowflake Version ^1.0.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bradietilley/laravel-snowflake contains the following files

Loading the files please wait ....