Skip to content

kduma-OSS/LV-eloquent-snowflakeable

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LV-eloquent-snowflakeable

Latest Stable Version Total Downloads Latest Unstable Version License

Eases using and generating SnowFlake ID's in Laravel Eloquent models.

Setup

Install it using composer

composer require kduma/eloquent-snowflakeable

Prepare models

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();

Usage

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.

Packagist

View this package on Packagist.org: kduma/eloquent-snowflakeable

About

Eases using and generating SnowFlake ID's in Laravel Eloquent models.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%