PHP code example of omaressaouaf / laravel-id-generator

1. Go to this page and download the library: Download omaressaouaf/laravel-id-generator 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/ */

    

omaressaouaf / laravel-id-generator example snippets


use Omaressaouaf\LaravelIdGenerator\IdGenerator;
use App\Models\User;

$id = IdGenerator::generate(Invoice::class, 'column_name', 5, 'INV-', '-2024');

echo $id; // INV-00001-2024

$id = IdGenerator::generate(Invoice::class, 'column_name', 5, 'INV-{YEAR}-');
echo $id; // INV-2025-00001

return [
    Invoice::class => [
        'field' => 'number',
        'padding' => 5,
        'prefix' => 'INV-',
        'suffix' => '-{YEAR}'
    ],
    'receipts' => [
        'field' => 'number',
        'padding' => 3,
        'prefix' => 'RC-',
    ]
];

$id = IdGenerator::generateFromConfig(Invoice::class);
echo $id; // INV-00001-2025
bash
php artisan vendor:publish --provider="Omaressaouaf\LaravelIdGenerator\LaravelIdGeneratorServiceProvider"