mitoop/laravel-snowflake 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mitoop/laravel-snowflake

最新稳定版本:v2.2.0

Composer 安装命令:

composer require mitoop/laravel-snowflake

包简介

README 文档

README

环境需求

  • PHP: ^8.2
  • Laravel: ^11|^12

安装

composer require mitoop/laravel-snowflake

发布配置文件

php artisan vendor:publish --provider="Mitoop\LaravelSnowflake\ServiceProvider"

snowflake.php配置文件

return [
    // 纪元时间
    'epoch' => '2023-08-01 00:00:00',
    // 数据中心id 范围:[0-31]. 为 null时, 随机取[0-31]的值
    'datacenter_id' => null,
    // 工作机器id 范围:[0-31]. 为 null时, 随机取[0-31]的值
    'worker_id' => null,
    // 序列号生成策略类 为 null 时, 使用随机数. 其他请指定类名如: RedisSequenceStrategy::class
    'sequence_strategy' => null,
];

可用方法

  1. 模型类可使用 HasSnowflakeIds trait, 支持多字段, 具体用法同 HasUuids, HasUlids Doc
  2. Str 快捷方法 \Str::snowflakeId()
  3. Blueprint方法
    Schema::create('tests', function (Blueprint $table){
         $table->snowflake()->primary();
         $table->snowflake('another_snowflake_id');
         $table->timestamps();
    });

统计信息

  • 总下载量: 170
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-17