mucts/laravel-snowflake is a Laravel package for 雪花算法:分布式环境,生成全局唯一的订单号.
It currently has 9 GitHub stars and 122 downloads on Packagist (latest version 1.4.2).
Install it with composer require mucts/laravel-snowflake.
Discover more Laravel packages by mucts
or browse all Laravel packages to compare alternatives.
Last updated

This Laravel package to generate 64 bit identifier like the snowflake within Twitter.
you will need to make sure your server meets the following requirements:
php ^7.4JSON PHP ExtensionOpenSSL PHP ExtensionGMP PHP ExtensionBCMath PHP Extensionlaravel/framework ^7.0composer require mucts/laravel-snowflake
$id = Snowflake::next();
$info = Snowflake::info($id);
Add the MuCTS\LaravelSnowflake\Models\Traits\Snowflake trait to your Eloquent model.
This trait make type snowflake of primary key. Trait will automatically set $incrementing property to false.
<?php
namespace App;
use MuCTS\LaravelSnowflake\Models\Traits\Snowflake;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Snowflake, 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');
$table->bigInteger('id')->unsigned()->primary();
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
If config/snowflake.php not exist, run below:
php artisan vendor:publish