PHP code example of qh-8 / laravel-snowflake

1. Go to this page and download the library: Download qh-8/laravel-snowflake library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

qh-8 / laravel-snowflake example snippets


use Qh\LaravelSnowflake\Snowflake;

$snowflake = app(Snowflake::class)->generate(); // or via Facade: Snowflake::generate()

// 93977444276639021

$data = app(Snowflake::class)->decode(93977444276639021); // or via Facade: Snowflake::decode(int $id)

//[
//  'binary_length' => 57,
//  'binary' => '101001101110111111111110011010111000000100001010100101101',
//  'binary_timestamp' => '10100110111011111111111001101011100',
//  'binary_sequence' => '010100101101',
//  'binary_worker_id' => '00001',
//  'binary_datacenter_id' => '00001',
//  'timestamp' => 22405968732,
//  'sequence' => 1325,
//  'worker_id' => 1,
//  'datacenter_id' => 1,
//  'epoch' => 1704067200000,
//  'datetime' => '2024-09-16T07:52:48+00:00',
//]

use \Qh\LaravelSnowflake\HasSnowflakeIds;

class User extends Model
{
    use HasSnowflakeIds;
    
    //
}