Skip to content

Releases: kra8/laravel-snowflake

v1.3.2

03 Feb 18:27
3dcdbb4
Compare
Choose a tag to compare
hotfixes (#18)

v1.3.1

03 Feb 18:00
fdad8e4
Compare
Choose a tag to compare
Fix reset startTimeout (#17)

v1.3.0

03 Feb 17:53
bc3cc04
Compare
Choose a tag to compare
  • Retry creating ID until timeout. #14
    timeout time is 1000 msec.

v1.2.3

30 Dec 00:23
Compare
Choose a tag to compare
  • Automatically set $incrementing to false when saving #13

No need to set incrementing:

-    public $incrementing = false;

v1.2.2

05 Dec 06:08
b02e837
Compare
Choose a tag to compare

Update depends.
Fix security alert.

v1.2.1

22 Nov 05:46
Compare
Choose a tag to compare

Fix path to config (#8)

v1.2.0

26 Sep 14:35
bf74e8e
Compare
Choose a tag to compare
  • Compatible with Laravel 6
  • Support Lumen

Create HasSnowflakePrimary Trait

16 Oct 13:17
Compare
Choose a tag to compare
Pre-release

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

14 Oct 02:24
Compare
Choose a tag to compare
v1.0.0 Pre-release
Pre-release
Merge branch 'master' of https://github.com/kra8/laravel-snowflake