Eases using and generating SnowFlake ID's in Laravel Eloquent models.
kduma/eloquent-snowflakeable is a Laravel package for eases using and generating snowflake id's in laravel eloquent models..
It currently has 0 GitHub stars and 0 downloads on Packagist.
Install it with composer require kduma/eloquent-snowflakeable.
Discover more Laravel packages by kduma
or browse all Laravel packages to compare alternatives.
Last updated
Eases using and generating SnowFlake ID's in Laravel Eloquent models.
Install it using composer
composer require kduma/eloquent-snowflakeable
Inside your model (not on top of file) add following lines:
use \KDuma\Eloquent\Snowflakeable;
In database create ulid string field. If you use migrations, you can use following snippet:
$table->unsignedBigInteger('sfid')->unique();
By default, it generates snowflake id on first save.
$model->regenerateSnowflake() - Generate new snowflake id. (Remember to save it by yourself)Model::whereSnowflake($id)->first() - Find by snowflake id. (whereSnowflake is query scope)Model::bySnowflake($id) - Find by snowflake id.$model->snowflake - Gets ParsedSnowflake object.$model->snowflake->getDateTime() - Gets Carbon object with snowflake creation time.View this package on Packagist.org: kduma/eloquent-snowflakeable