PHP code example of jetcod / eloquent-keygen

1. Go to this page and download the library: Download jetcod/eloquent-keygen 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/ */

    

jetcod / eloquent-keygen example snippets




namespace App\Models;

use Jetcod\Eloquent\Model as EloquentModel;

class YourModel extends EloquentModel
{
    // Your model code here
}



namespace App\Models;

use Illuminate\Database\Eloquent\Model as EloquentModel;
use Jetcod\Eloquent\Traits\Snowflake;

class YourModel extends EloquentModel
{
    use Snowflake;
}



namespace App\Models;

use Jetcod\Eloquent\Model as EloquentModel;

class AnotherModel extends EloquentModel
{
    protected function snowflake(): bool
    {
        return false;
    }

    // Your model code here
}



use Godruoyi\Snowflake\LaravelSequenceResolver;

return [
    'attributes' => [
        /*
        |------------------------------------------------------------------
        | This represents the datacenter id used to generate snowflake ids.
        |------------------------------------------------------------------
        */

        'datacenter' => env('SNOWFLAKE_DATACENTER_ID', 1),

        /*
        |--------------------------------------------------------------
        | This represents the worker id used to generate snowflake ids.
        |--------------------------------------------------------------
        */

        'worker' => env('SNOWFLAKE_WORKER_ID', 1),

        /*
        |--------------------------------------------------------------------------------------------------------
        | This represents the sequence resolver class. It is to ensure that sequence-number generated in the same
        | millisecond of the same node is unique.
        |
        | Avaialable resolvers:
        |   1. Godruoyi\Snowflake\RandomSequenceResolver
        |   2. Godruoyi\Snowflake\FileLockResolver
        |   3. Godruoyi\Snowflake\LaravelSequenceResolver
        |--------------------------------------------------------------------------------------------------------
        */

        'sequence_resolver' => env('SNOWFLAKE_SEQUENCE_RESOLVER', LaravelSequenceResolver::class),

        'file_lock_directory' => env('SNOWFLAKE_File_LOCK_DIRECTORY', null),  // Default is null, means use <app_path>/storage/snowflake directory.
    ],
];
sh
php artisan vendor:publish --provider="eloquent-key-generator-config"