kduma/eloquent-snowflakeable
Composer 安装命令:
composer require kduma/eloquent-snowflakeable
包简介
Eases using and generating SnowFlake ID's in Laravel Eloquent models.
README 文档
README
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. (whereSnowflakeis query scope)Model::bySnowflake($id)- Find by snowflake id.$model->snowflake- GetsParsedSnowflakeobject.$model->snowflake->getDateTime()- GetsCarbonobject with snowflake creation time.
Packagist
View this package on Packagist.org: kduma/eloquent-snowflakeable
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-29