kra8/laravel-snowflake
Composer 安装命令:
composer require kra8/laravel-snowflake
包简介
Snowflake for Laravel and Lumen.
关键字:
README 文档
README
This Laravel package to generate 64 bit identifier like the snowflake within Twitter.
Laravel Installation
composer require "kra8/laravel-snowflake"
php artisan vendor:publish --provider="Kra8\Snowflake\Providers\LaravelServiceProvider"
Lumen Installation
- Install via composer
composer require "kra8/laravel-snowflake"
- Bootstrap file changes Add the following snippet to the bootstrap/app.php file under the providers section as follows:
// Add this line $app->register(Kra8\Snowflake\Providers\LumenServiceProvider::class);
Usage
Get instance
$snowflake = $this->app->make('Kra8\Snowflake\Snowflake');
or
$snowflake = app('Kra8\Snowflake\Snowflake');
Generate snowflake identifier
$id = $snowflake->next();
Usage with Eloquent
Add the Kra8\Snowflake\HasSnowflakePrimary trait to your Eloquent model.
This trait make type snowflake of primary key. Trait will automatically set $incrementing property to false.
<?php namespace App; use Kra8\Snowflake\HasSnowflakePrimary; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use HasSnowflakePrimary, Notifiable; }
Column type id is supported.
/** * Run the migrations. * * @return void */ public function up() { Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('email')->unique(); $table->string('password'); $table->rememberToken(); $table->timestamps(); }); }
JavaScript support
Since JavaScript cannot handle 64-bit integers, there is also HasShortPrimary, which creates an ID for a 53-bit integer that can be handled by JavaScript.
To use it, simply change HasSnowflakePrimary to HasShortPrimary.
<?php namespace App; use Kra8\Snowflake\HasShortflakePrimary; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use HasShortflakePrimary, Notifiable; }
Configuration
If config/snowflake.php not exist, run below:
php artisan vendor:publish
Licence
kra8/laravel-snowflake 适用场景与选型建议
kra8/laravel-snowflake 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 455.44k 次下载、GitHub Stars 达 191, 最近一次更新时间为 2017 年 10 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「snowflake」 「lumen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kra8/laravel-snowflake 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kra8/laravel-snowflake 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kra8/laravel-snowflake 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHP library for generating and working with identifiers, including UUIDs, ULIDs, and Snowflakes
An ID Generator for PHP based on Snowflake Algorithm (Twitter announced).
Snowflake database driver for Laravel using REST API - no PDO extension required
Alfabank REST API integration
The best
This package to generate 64 bit identifier, use snowflakes from Twitter.
统计信息
- 总下载量: 455.44k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 197
- 点击次数: 30
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-14