PHPackages                             ufucms/laravel-snowflake - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ufucms/laravel-snowflake

ActiveLibrary

ufucms/laravel-snowflake
========================

分布式唯一ID，基于雪花算法。

1.0.3(2y ago)0881[3 PRs](https://github.com/ufucms/laravel-snowflake/pulls)MITPHPPHP ^8.0|^8.1

Since Aug 9Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ufucms/laravel-snowflake)[ Packagist](https://packagist.org/packages/ufucms/laravel-snowflake)[ Docs](https://github.com/ufucms/laravel-snowflake)[ RSS](/packages/ufucms-laravel-snowflake/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Laravel Snowflake
=================

[](#laravel-snowflake)

这个 Laravel 包生成 64 位标识符，就像 Twitter 中的雪花一样。

Laravel 安装
==========

[](#laravel-安装)

```
composer require "ufucms/laravel-snowflake"

php artisan vendor:publish --provider="Ufucms\Snowflake\Providers\LaravelServiceProvider"

```

Lumen 安装
========

[](#lumen-安装)

- Install via composer

```
composer require "ufucms/laravel-snowflake"

```

- Bootstrap file changes 将以下代码段添加到 providers 部分下的 bootstrap/app.php 文件中，如下所示：

```
// Add this line
$app->register(Ufucms\Snowflake\Providers\LumenServiceProvider::class);
```

Usage
=====

[](#usage)

Get instance

```
use Ufucms\Snowflake\Snowflake;

$snowflake = new Snowflake();
```

or

```
$snowflake = $this->app->make('Ufucms\Snowflake\Snowflake');
```

or

```
$snowflake = app('Ufucms\Snowflake\Snowflake');
```

Generate snowflake identifier

```
$id = $snowflake->nextId();

```

or

```
$id = $snowflake->id();

```

or

```
$id = Snowflake::nextId();

```

Usage with Eloquent
===================

[](#usage-with-eloquent)

将 `Ufucms\Snowflake\HasSnowflakePrimary` 特征添加到您的 Eloquent 模型中。 此特征使主键类型为`snowflake`。 Trait 会自动将 $incrementing 属性设置为 false。

```
