承接 kra8/laravel-snowflake 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

kra8/laravel-snowflake

最新稳定版本:v2.4.1

Composer 安装命令:

composer require kra8/laravel-snowflake

包简介

Snowflake for Laravel and Lumen.

README 文档

README

Build Status Latest Stable Version License

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

MIT licence

统计信息

  • 总下载量: 362.27k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 183
  • 点击次数: 1
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 177
  • Watchers: 1
  • Forks: 22
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-14