Snowflake for Laravel and Lumen.

v2.0.3 2021-12-14 02:37 UTC

This package is auto-updated.

Last update: 2022-01-16 05:28:08 UTC


Build Status Latest Stable Version License

This Laravel package to generate 64 bit identifier like the snowflake within Twitter.

Laravel Installation

composer require "kra8/laravel-snowflake"

php artisan vendor:publish --provider="Kra8\Snowflake\Providers\LaravelServiceProvider"

Lumen Installation

  • Install via composer
composer require "kra8/laravel-snowflake"
  • Bootstrap file changes Add the following snippet to the bootstrap/app.php file under the providers section as follows:
// Add this line


Get instance

$snowflake = $this->app->make('Kra8\Snowflake\Snowflake');


$snowflake = app('Kra8\Snowflake\Snowflake');

Generate snowflake identifier

$id = $snowflake->next();

Usage with Eloquent

Add the Kra8\Snowflake\HasSnowflakePrimary trait to your Eloquent model. This trait make type snowflake of primary key. Trait will automatically set $incrementing property to false.

namespace App;

use Kra8\Snowflake\HasSnowflakePrimary;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
    use HasSnowflakePrimary, Notifiable;

Finally, in migrations, set the primary key to bigInteger, unsigned and primary.

 * Run the migrations.
 * @return void
public function up()
    Schema::create('users', function (Blueprint $table) {
        // $table->increments('id');


If config/snowflake.php not exist, run below:

php artisan vendor:publish


MIT licence