All Projects → kra8 → laravel-snowflake

kra8 / laravel-snowflake

Licence: MIT license
This Laravel package to generate 64 bit identifier like the snowflake within Twitter.

Programming Languages

PHP
23972 projects - #3 most used programming language
Dockerfile
14818 projects
Makefile
30231 projects

Projects that are alternatives of or similar to laravel-snowflake

Laravel-Auto-Hard-Deleter
Laravel and Lumen Auto Hard Deleter
Stars: ✭ 34 (-63.83%)
Mutual labels:  lumen, laravel-package, lumen-package
response
Response HTTP package for Simfony, Laravel, Lumen and PHP 7 with standard REST API
Stars: ✭ 14 (-85.11%)
Mutual labels:  lumen, laravel-package, lumen-package
Laravel Url Shortener
Powerful URL shortening tools in Laravel
Stars: ✭ 80 (-14.89%)
Mutual labels:  lumen, laravel-package
baserepo
Base repository
Stars: ✭ 71 (-24.47%)
Mutual labels:  lumen, lumen-package
video-downloader
Video Downloader for Facebook.
Stars: ✭ 63 (-32.98%)
Mutual labels:  lumen, laravel-package
Laravel Postal Code Validation
Worldwide postal code validation for Laravel and Lumen
Stars: ✭ 278 (+195.74%)
Mutual labels:  lumen, laravel-package
Jwt Auth Guard
JWT Auth Guard for Laravel and Lumen Frameworks.
Stars: ✭ 319 (+239.36%)
Mutual labels:  lumen, laravel-package
Laravel Sensitive
过滤敏感词汇的laravel包,使用DFA算法
Stars: ✭ 63 (-32.98%)
Mutual labels:  lumen, laravel-package
Laravel Source Encrypter
Laravel and Lumen Source Code Encrypter
Stars: ✭ 175 (+86.17%)
Mutual labels:  lumen, laravel-package
apitest
this is a tool for testing Laravel REST API
Stars: ✭ 11 (-88.3%)
Mutual labels:  laravel-package
Laravel-FluentLogger
fluent logger for laravel (with Monolog handler for Fluentd)
Stars: ✭ 55 (-41.49%)
Mutual labels:  lumen
aliyun-oss-laravel
Laravel 的 Aliyun OSS 扩展, 支持 Laravel 9. Alibaba Cloud Object Storage Service For Laravel.
Stars: ✭ 91 (-3.19%)
Mutual labels:  laravel-package
firebase-php
Firebase Realtime Database PHP Wrapper
Stars: ✭ 41 (-56.38%)
Mutual labels:  laravel-package
laravel-helper-functions
Laravel-specific and pure PHP Helper Functions.
Stars: ✭ 106 (+12.77%)
Mutual labels:  laravel-package
DBTestCompare
Application to compare results of two SQL queries
Stars: ✭ 15 (-84.04%)
Mutual labels:  snowflake
voyager-page-blocks
A module to provide page blocks for Voyager 📝
Stars: ✭ 80 (-14.89%)
Mutual labels:  laravel-package
meituan-pub-union
🌈 美团分销联盟 PHP-SDK
Stars: ✭ 19 (-79.79%)
Mutual labels:  laravel-package
cache
Laravel & Lumen Cache Service | File and Redis cache system
Stars: ✭ 19 (-79.79%)
Mutual labels:  lumen
entrust
This package is based on Zizaco/entrust to support Laravel/Lumen 6+ versions
Stars: ✭ 22 (-76.6%)
Mutual labels:  lumen
go-snowflake
❄ An Lock Free ID Generator for Golang based on Snowflake Algorithm (Twitter announced).
Stars: ✭ 206 (+119.15%)
Mutual labels:  snowflake

Laravel Snowflake

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].