New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

omaressaouaf/laravel-id-generator

Generate custom incremental unique ids for Laravel
10,869 59
Install
composer require omaressaouaf/laravel-id-generator
Latest Version:1.4.0
PHP:^8.2|^8.3|^8.4|^8.5
Laravel:10 – 13
License:MIT
Last Updated:Jul 11, 2026
Links: GitHub  ·  Packagist
Maintainer: omaressaouaf

Laravel ID Generator

Latest Stable Version License Tests

A Laravel package for generating custom auto-incrementing IDs with prefixes, suffixes, and date-based placeholders.

🚀 Features

  • Auto-increment ID generation for any column.
  • Allow custom prefixes & suffixes & padding
  • Supports {DATE}, {MONTH}, and {YEAR} placeholders.

📥 Installation

Install via Composer:

composer require omaressaouaf/laravel-id-generator

📌 Usage

Basic Example

Generate an ID with a prefix and suffix and padding:

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

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

echo $id; // INV-00001-2024

Dynamic Placeholders

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

Initial starting point

Start from a specific number if there is no ID found in DB

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

Generators

After installation, you can publish the package configuration file using:

php artisan vendor:publish --provider="Omaressaouaf\LaravelIdGenerator\LaravelIdGeneratorServiceProvider"

This will create a configuration file in config/laravel-id-generator.php, allowing you define custom generators for different tables or models.

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

Then you can use the generator

$id = IdGenerator::generateFromConfig(Invoice::class);
echo $id; // INV-00001-2025

🛠️ Testing

Run unit tests:

composer test

📜 License

This package is licensed under the MIT License.

Related Packages

valorin/random

Random is a simple helper package designed to make it easy to generate a range o...

479,812 234
php
cline/variable-keys

Laravel Blueprint macros for variable primary key and morph types

25,882 0
php
cline/struct

Lean, attribute-driven Laravel data objects with explicit validation and Eloquen...

21,144 0
php
cline/toggl

Advanced feature flag management with strategies, time bombs, and groups

14,699 0
php
cline/sequencer

Sequential migration and operation orchestration for Laravel

14,448 0
php

Version History

Version Released PHP Laravel License
1.4.0 ^8.2|^8.3|^8.4|^8.5 ^10.0||^11.0||^12.0|^13.0 MIT
1.3.0 ^8.2|^8.3|^8.4 ^10.0||^11.0||^12.0 MIT
1.2.1 ^8.2|^8.3|^8.4 ^10.0||^11.0||^12.0 MIT
1.2.0 ^8.2|^8.3|^8.4 ^10.0||^11.0||^12.0 MIT
1.0.1 ^8.2|^8.3|^8.4 ^10.0||^11.0||^12.0 MIT