Laravel Snowflake Versions Save

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

v1.3.2

4 years ago

v1.3.1

4 years ago

v1.3.0

4 years ago
  • Retry creating ID until timeout. #14 timeout time is 1000 msec.

v1.2.3

4 years ago
  • Automatically set $incrementing to false when saving #13

No need to set incrementing:

-    public $incrementing = false;

v1.2.2

4 years ago

Update depends. Fix security alert.

v1.2.1

4 years ago

Fix path to config (#8)

v1.2.0

4 years ago
  • Compatible with Laravel 6
  • Support Lumen

v1.1.0

6 years ago

Update v1.1.0

  • Add HasSnowflakePrimary trait.

Feature

$user = new User();
$user->name = 'example';
$user->email = '[email protected]';
$user->password = '123456789';
$user->save();

echo $user->id; // snowflake id(1282679165292544)

Usage

Add the Kra8\Snowflake\HasSnowflakePrimary trait to your Eloquent model. This trait make type snowflake of primary key. Don't forget to set the Auto increment property to false.

<?php
namespace App;

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

class User extends Authenticatable
{
    use HasSnowflakePrimary, Notifiable;

    /**
     * Indicates if the IDs are auto-incrementing.
     *
     * @var bool
     */
    public $incrementing = false;
}

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

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('users', function (Blueprint $table) {
        // $table->increments('id');
        $table->bigInteger('id')->primary();
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });
}

v1.0.0

6 years ago