Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Id Generator

Id Generator Laravel Package

alimarchal/id-generator

Generate unique, professional document IDs in Laravel (PREFIX-YYYYMMDD-XXXX) with transaction safety and race-condition protection. Ideal for invoices, complaints, orders, quotations, and more. Compatible with Laravel 11/12, scalable for high volume.

View on GitHub
Deep Wiki
Context7

A Laravel package to generate unique, prefixed IDs with database transaction safety

Frequently asked questions about Id Generator
How does this package prevent race conditions when generating IDs?
The package uses database transactions and row locking to ensure thread safety. When generating an ID, it locks the relevant row in the `id_prefixes` table, increments the counter, and releases the lock—all within a single transaction. This guarantees no two requests will generate the same ID simultaneously.
Can I use custom ID formats beyond the default `PREFIX-YYYYMMDD-XXXX`?
Yes, the package is extensible. You can override the default format by binding your own ID generator class to the service container. The core logic remains transaction-safe, but you can customize how the prefix, date, and sequence are combined.
Does this package work with Laravel 12 and PHP 8.3?
Yes, the package is fully compatible with Laravel 11 and 12, as well as PHP 8.2 and 8.3. It follows Laravel’s latest conventions and has been tested with these versions. Always check the package’s GitHub for the latest compatibility updates.
How do I add a new prefix (e.g., for 'receipts') to the `id_prefixes` table?
Run the migration to create the `id_prefixes` table, then insert your custom prefix using a raw query, Eloquent, or a seed file. For example: `DB::table('id_prefixes')->insert(['name' => 'receipt', 'prefix' => 'RCP']);`. The package includes sample prefixes for invoices, complaints, and quotations by default.
Will this package impact performance under high concurrency (e.g., 10,000+ requests per minute)?
No, the package is optimized for high-volume ID generation. It uses efficient database queries with row locking and transactions, and benchmarks show it handles 10,000+ IDs per minute without performance degradation. The package’s test suite includes concurrency tests to validate this.
Can I integrate this with existing custom ID logic in my Laravel app?
Yes, the package is designed for seamless integration. Replace your custom ID generation logic with the package’s helper function, `generateUniqueId()`, and update your models or services. The package provides a drop-in replacement for manual numbering logic while adding transaction safety and professional formatting.
How do I test this package in my Laravel application?
The package includes Testbench examples for testing controllers and services. Use Pest or PHPUnit to mock the `IdGenerator` service and verify ID generation logic. The package’s test suite covers edge cases like concurrent requests, ensuring your tests can replicate real-world scenarios.
Is there a way to log or monitor ID generation for auditing purposes?
Currently, the package focuses on core functionality, but you can extend it by wrapping the `generateUniqueId()` function in your own logging layer. For example, log the generated ID, timestamp, and prefix to a dedicated table or monitoring tool like Datadog or Prometheus.
What databases does this package support, and are there any limitations?
The package supports MySQL, PostgreSQL, and SQLite out of the box. It uses standard SQL queries without vendor-specific syntax, so it works across these databases. However, always test in your production environment to ensure compatibility with your specific database configuration.
Are there alternatives to this package for generating unique IDs in Laravel?
Yes, alternatives include using Laravel’s built-in UUID generation (`Str::uuid()`) or packages like `webklex/uuid` for UUIDs, or `spatie/laravel-activitylog` for activity-based IDs. However, this package uniquely combines professional formatting, transaction safety, and prefix-based organization, making it ideal for document numbering like invoices or orders.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope