PHPackages                             kra8/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. kra8/laravel-snowflake

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kra8/laravel-snowflake
======================

Snowflake for Laravel and Lumen.

v2.5.0(2mo ago)188402.3k↓10.5%23[3 PRs](https://github.com/kra8/laravel-snowflake/pulls)6MITPHPPHP ^8.2CI passing

Since Oct 14Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/kra8/laravel-snowflake)[ Packagist](https://packagist.org/packages/kra8/laravel-snowflake)[ Docs](https://github.com/kra8/laravel-snowflake)[ GitHub Sponsors](https://github.com/kra8)[ RSS](/packages/kra8-laravel-snowflake/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (26)Used By (6)

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

[](#laravel-snowflake)

[![Build Status](https://camo.githubusercontent.com/5dd2eab3b7ee26c11ba52ef84bbc2eab469fa7ec2bc2a99adf00c569cbaa1660/68747470733a2f2f7472617669732d63692e6f72672f6b7261382f6c61726176656c2d736e6f77666c616b652e7376673f6272616e63683d73657475702d747261766973)](https://travis-ci.org/kra8/laravel-snowflake)[![Latest Stable Version](https://camo.githubusercontent.com/0678ef161f9f1d55018ad804779763fefa501eab15582e72c5ad64d082b832c2/68747470733a2f2f706f7365722e707567782e6f72672f6b7261382f6c61726176656c2d736e6f77666c616b652f762f737461626c65)](https://packagist.org/packages/kra8/laravel-snowflake)[![License](https://camo.githubusercontent.com/af6ebd71c90b684653649ff270b6d5d0bf4c6e33ad60e6d17145cc8ce4277cf9/68747470733a2f2f706f7365722e707567782e6f72672f6b7261382f6c61726176656c2d736e6f77666c616b652f6c6963656e7365)](https://packagist.org/packages/kra8/laravel-snowflake)

This Laravel package to generate 64 bit identifier like the snowflake within Twitter.

Laravel Installation
====================

[](#laravel-installation)

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

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

```

Lumen Installation
==================

[](#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
=====

[](#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
===================

[](#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.

```
