indragunawan/sequence-bundle
SequenceBundle provides configurable, database-backed sequence generation for PHP apps, with support for prefixes, suffixes, zero-padding, reset periods, and concurrency-safe counters—ideal for invoice, order, and document numbers.
First, establish what you actually have. Despite the framing, indragunawan/sequence-bundle is a Symfony bundle, not a Laravel package — it ships no service provider, facade, or config file that Laravel's container will auto-discover. If the project is genuinely Symfony, the setup is:
composer require indragunawan/sequence-bundle.config/bundles.php (Symfony Flex usually does this).vendor/indragunawan/sequence-bundle/DependencyInjection/Configuration.php first — that is the authoritative list of options (format/prefix/suffix, reset period, storage backend).Resources/config/services.yaml (or .xml) to learn the generator's service id and constructor arguments before wiring anything.The first use case to validate is a formatted, human-readable sequential identifier — e.g. an invoice or order number like INV/2024/000123 — that increments atomically and resets on a schedule. Prove that end-to-end (generate two IDs, confirm they increment and persist) before building on it.
If the project is Laravel: stop. There is no supported path to boot a Symfony bundle inside Laravel's container. The realistic options are (a) copy the sequence-generation logic into a small Laravel service, or (b) evaluate a Laravel-native alternative. Treat the bundle as a reference implementation, not a dependency.
Config-driven formatting. Define the number format declaratively (prefix, date token, zero-padded counter, reset granularity) rather than concatenating strings in application code. Centralising the format means adding a new document type is a config change, not a code change.
Inject the generator, don't new it. In Symfony, autowire the generator service into the service that creates the entity (order/invoice handler). If the service id isn't guessable, it isn't autowireable — bind it explicitly or define an alias.
Generate inside the persistence transaction. The sequence read-and-increment and the entity insert should commit together. If you generate the number in a controller and persist later, you invite duplicates under concurrency and orphaned numbers on validation failure.
Use it for display identifiers, not primary keys. Keep auto-increment/UUID primary keys for referential integrity and joins; use the sequence for the value humans quote on the phone.
Wrap it behind your own interface. Define DocumentNumberGenerator in your domain and adapt the bundle's service to it. This isolates the (old, low-adoption) dependency so you can swap implementations without touching call sites — and it's the seam you'd use to port to Laravel later.
Test fixtures must reset state. Seed or truncate the sequence storage between tests, otherwise assertions on 000001 depend on test execution order.
Bundle class, DI extension, and compiler passes do nothing in Laravel. Don't spend a day trying to bridge it; port the concept.SELECT ... FOR UPDATE, a unique constraint with retry, or nothing. Under load, a naive read-then-write will hand out duplicate numbers. Test with parallel workers before trusting it.bin/console debug:container <service> to confirm the service exists and its arguments; debug:config to verify your config was merged; enable SQL logging to watch the actual increment statement.How can I help you explore Laravel packages today?