2017 © Pedro Peláez
 

library laravel-snowflake

Snowflake for Laravel.

image

kra8/laravel-snowflake

Snowflake for Laravel.

  • Wednesday, October 18, 2017
  • by kra8
  • Repository
  • 1 Watchers
  • 3 Stars
  • 362 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 83 % Grown

The README.md

Laravel Snowflake

Build Status Latest Stable Version License, (*1)

This Laravel package to generate 64 bit identifier like the snowflake within Twitter., (*2)

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: ``` php // Add this line $app->register(Kra8\Snowflake\Providers\LumenServiceProvider::class);

# Usage Get instance ``` php $snowflake = $this->app->make('Kra8\Snowflake\Snowflake');

or ``` php $snowflake = app('Kra8\Snowflake\Snowflake');, (*3)


Generate snowflake identifier

$id = $snowflake->next();, (*4)

# 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
<?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., (*5)

``` php /** * 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(); }); }, (*6)


# 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 <?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:, (*7)

php artisan vendor:publish

Licence

MIT licence, (*8)

The Versions

18/10 2017

dev-master

9999999-dev https://github.com/kra8/laravel-snowflake

Snowflake for Laravel.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Koki Asai

laravel snowflake

18/10 2017

dev-setup-travis

dev-setup-travis https://github.com/kra8/laravel-snowflake

Snowflake for Laravel.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Koki Asai

laravel snowflake

16/10 2017

v1.1.0

1.1.0.0 https://github.com/kra8/laravel-snowflake

Snowflake for Laravel.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Koki Asai

laravel snowflake

14/10 2017

v1.0.0

1.0.0.0 https://github.com/kra8/laravel-snowflake

Snowflake for Laravel.

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

by Koki Asai

laravel snowflake