hafael/laraflake
LaraFlake
LaraFlake is a Laravel 5.x Package based on Twitter Snowflake ID Generator (64 bit ID).
- Generate unique identifiers like 4685142323047173636 (64bit)
- 41bit for time
- 10bits for shard database identifier from 1 to 512
- 12bits for randomic number from 1 to 2048
Only supports MySQL database. :(
Waiting for your pull request to solve this issue...
How to use
Run the composer require command from your terminal:
$ composer require hafael/laraflake
Open rootproject/config/app.php and register the required service provider above your application providers.
'providers' => [
/*
* Application Service Providers...
*/
...
Hafael\LaraFlake\LaraFlakeServiceProvider::class,
],
Run Artisan command to publish vendor config file in rootproject/config/laraflake.php
$ php artisan vendor:publish --provider="Hafael\LaraFlake\LaraFlakeServiceProvider"
Import the LaraFlakeTrait in your model and set $incrementing to false:
class User extends Authenticatable
{
use LaraFlakeTrait;
protected $table = "users";
/**
* Indicates if the IDs are auto-incrementing.
* @var bool
*/
public $incrementing = false;
...
And update the migration files to use BIGINT(20) UNSIGNED:
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigInteger('id')->unsigned()->primary();
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
...
Development
Want to contribute? Great! Just create a pull request.
Todos
- Write Tests
- Write Benchmark Tests
- Implement support for other databases
License
Apache 2.0
Inspiration
Inspired on simplicity from Particle by Silviu Schiau.
Related Packages
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v1.2.5 | >=5.3.0 | >=5.3.0 | Apache-2.0 | |
| v1.2.4 | >=5.3.0 | >=5.3.0 | Apache-2.0 | |
| v1.2.3 | >=5.3.0 | >=5.3.0 | Apache-2.0 | |
| v1.2.2 | >=5.3.0 | >=5.3.0 | Apache-2.0 | |
| v1.2.1 | >=5.3.0 | >=5.3.0 | Apache-2.0 | |
| v1.2.0 | >=5.3.0 | >=5.3.0 | Apache-2.0 | |
| v1.1.0 | >=5.3.0 | >=5.3.0 | Apache-2.0 | |
| v1.0.0 | >=5.3.0 | 5.3.* | Apache-2.0 | |
| v0.1.0 | >=5.3.0 | 5.2.* | Apache-2.0 |
Pre-releases (1)
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v0.2-alpha | >=5.3.0 | 5.2.* | Apache-2.0 |