PHPackages                             vsent/codegenerator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. vsent/codegenerator

ActiveLaravel-package[Utility &amp; Helpers](/categories/utility)

vsent/codegenerator
===================

A robust, flexible, and pattern-based unique code generator for Laravel applications.

v1.0.1(11mo ago)01MITPHPPHP ^8.2

Since Jun 9Pushed 11mo agoCompare

[ Source](https://github.com/VseVepl/codegenerator)[ Packagist](https://packagist.org/packages/vsent/codegenerator)[ RSS](/packages/vsent-codegenerator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

VsE/codegenerator - Dynamic Unique Code Generator for Laravel A robust, flexible, and pattern-based package to generate unique identifiers (codes) for various entities within your Laravel application (e.g., order numbers, invoice IDs, tracking codes). It features thread-safe sequence management, configurable patterns, and supports different types of unique components (sequential, random, UUIDs).

Installation Add to your project: If developing locally within your packages directory: Add the following to your main composer.json file in the autoload section:

"autoload": { "psr-4": { "App\\": "app/", "vsent\\\\Codegenerator\\": "packages/vse/codegenerator/src/" // Add this line } }, "repositories": \[ { "type": "path", "url": "./packages/vse/codegenerator" } \]

Then run composer dump-autoload.

If installing via Packagist (after publishing your package):

composer require vse/codegenerator

Publish Configuration &amp; Migrations: After installation, publish the package's configuration file and database migrations:

php artisan vendor:publish --tag=codegenerator-config php artisan vendor:publish --tag=codegenerator-migrations

This will create config/codegenerator.php and a migration file in database/migrations.

Run Migrations: Execute the migrations to create the code\_sequences table:

php artisan migrate

Configuration (config/codegenerator.php) The config/codegenerator.php file (published in step 2) is where you define global settings and specific patterns for your codes. Refer to the extensive comments within that file for detailed explanations of each option and placeholder.

Usage You can use the CodeGenerator Facade to generate codes.

1. Generating a Predefined Code Type This is the most common and recommended way to generate codes, using patterns defined in your config/codegenerator.php.

use vsent\\Codegenerator\\Facades\\CodeGenerator;

// Generate an Order Code (uses 'order' pattern from config) try { $orderCode = CodeGenerator::generateFor('order'); // Example: ORD-250609-HQ-0001 } catch (\\RuntimeException $e) { // Handle error (e.g., max attempts reached, database error) echo "Error generating order code: " . $e-&gt;getMessage(); }

// Generate an Invoice Number (uses 'invoice' pattern from config) try { $invoiceNumber = CodeGenerator::generateFor('invoice'); // Example: INV-202506-MUM-00001 } catch (\\RuntimeException $e) { echo "Error generating invoice: " . $e-&gt;getMessage(); }

// Generate a Tracking ID (uses 'tracking\_id' pattern, which generates UUIDs) try { $trackingId = CodeGenerator::generateFor('tracking\_id'); // Example: TRK-a1b2c3d4-e5f6-7890-1234-567890abcdef } catch (\\RuntimeException $e) { echo "Error generating tracking ID: " . $e-&gt;getMessage(); }

2. Generating with Runtime Overrides You can temporarily override specific configuration settings for a single generation call.

use vsent\\Codegenerator\\Facades\\CodeGenerator;

// Generate a Purchase Order code, but specify a different location for this instance try { $poCodeForLondon = CodeGenerator::generateFor('purchase\_order', \[ 'location' =&gt; 'LDN', // Override the default 'NYC' for this generation 'sequence\_length' =&gt; 6 // Override default 5-digit sequence \]); // Example: PO/LDN/20250609/000001 } catch (\\RuntimeException $e) { echo "Error generating PO code: " . $e-&gt;getMessage(); }

3. Generating with an Inline (Ad-Hoc) Pattern For one-off or dynamic code structures not defined in the config, you can pass the pattern directly.

use vsent\\Codegenerator\\Facades\\CodeGenerator;

// Generate a custom short code for an event registration try { $eventCode = CodeGenerator::generateFor('EVT-{DATE:md}-{RANDOM:4}', \[ 'type' =&gt; 'EVENT', // Type used for placeholder and sequence tracking if applicable 'code\_length' =&gt; 12 // Ensure total length is 12 \]); // Example: EVT-0609-ABCD0000 } catch (\\RuntimeException $e) { echo "Error generating event code: " . $e-&gt;getMessage(); }

4. Confirming Usage for Sequential Codes (Crucial!) For any code generated using the {SEQUENCE} placeholder, it's CRUCIAL to call confirmUsage() once the code has been successfully processed and committed in your application (e.g., after saving an order to the database). This updates the sequence in the code\_sequences table, ensuring proper sequential numbering and preventing gaps in your confirmed sequences if a generated code isn't actually used.

use vsent\\Codegenerator\\Facades\\CodeGenerator; use Illuminate\\Support\\Facades\\DB; // Example of wrapping in a transaction

try { DB::beginTransaction();

```
$orderCode = CodeGenerator::generateFor('order');
// ... logic to save the order to your 'orders' table using $orderCode ...

if (CodeGenerator::confirmUsage($orderCode)) {
    DB::commit();
    echo "Order created and code confirmed: " . $orderCode;
} else {
    DB::rollBack();
    echo "Failed to confirm order code usage. Transaction rolled back.";
}

```

} catch (\\RuntimeException $e) { DB::rollBack(); echo "Error during order creation: " . $e-&gt;getMessage(); }

// Note: For codes generated with {UUID} or {RANDOM}, confirmUsage() is generally not needed, // as their uniqueness is inherent and not managed by a shared sequence counter.

Contributing Feel free to open issues or pull requests on the GitHub repository.

License This package is open-sourced software licensed under the MIT license.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance51

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

341d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ddaa0cadb2b42b56b533954b3c10920b0cbf406864a9cb283c9ff63ab448d34c?d=identicon)[VseVepl](/maintainers/VseVepl)

---

Top Contributors

[![VseVepl](https://avatars.githubusercontent.com/u/215473430?v=4)](https://github.com/VseVepl "VseVepl (6 commits)")

---

Tags

laravelcode generatorunique codessequence-generatorinvoice-numbersorder-idstracking-ids

### Embed Badge

![Health badge](/badges/vsent-codegenerator/health.svg)

```
[![Health](https://phpackages.com/badges/vsent-codegenerator/health.svg)](https://phpackages.com/packages/vsent-codegenerator)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
