Download the PHP package vimatech/laravel-document-numbering without Composer

On this page you can find all versions of the php package vimatech/laravel-document-numbering. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-document-numbering

Laravel Document Numbering

Document numbers that survive concurrency, gap-free by default

CI Latest Version on Packagist Total Downloads License

Allocate sequential numbers for invoices, quotes and credit notes, using database transactions and row locks. Under concurrent requests two callers never take the same number, and a type with gap_free: true (the default) never leaves a hole in its sequence either. Whether a numbering scheme meets the rules of your jurisdiction is for you to establish; see Database notes for what each engine guarantees.

Why Laravel Document Numbering?

Invoices and credit notes are commonly numbered in an unbroken sequence. Getting that right under load is harder than it looks. Most Laravel apps eventually need to answer:

Laravel Document Numbering provides a small, database-backed layer for exactly that: it leans on database transactions and row locks rather than hoping races never happen.

Feature Matrix

Feature Supported
Configurable patterns (INV-{YYYY}-{seq:5}) ✅
Per-scope counters (company / tenant / branch) ✅
Period resets (yearly, monthly, never) ✅
Gap-free mode (transaction-bound) ✅
"Has this sequence been used?" across all periods ✅
Fast-sequential mode ✅
Concurrency-safe (row locks) ✅
Eloquent trait, event & facade ✅
Database-portable (MySQL, PostgreSQL, SQLite) ⚠️
Octane / FrankenPHP safe ✅
UI ❌

⚠️ The package writes no engine-specific SQL, but the automated suite runs on SQLite only, where lockForUpdate() compiles to an empty string. Read Database notes before relying on the row lock in production.

Requirements

Installation

Publish and run the migration:

Publish the config (optional):

Configuration

config/numbering.php defines a counter strategy per document type:

Pattern tokens

Token Meaning Example
{YYYY} 4-digit year 2026
{YY} 2-digit year 26
{MM} 2-digit month 06
{seq:n} sequence value, zero-padded to n 00042

Everything outside a token is literal text. A sequence longer than its padding is not truncated ({seq:3} with value 12345 → 12345).

Reset policies

The reset policy decides when the counter restarts at 1, by computing a period key. Two allocations share a counter only when their (scope, type, period_key) match.

Policy Period key (for 2026-06) Restarts
ResetPolicy::Never all never
ResetPolicy::Yearly 2026 each year
ResetPolicy::Monthly 2026-06 each month

Tip: include the matching date token in the pattern ({YYYY} for yearly, {YY}{MM} for monthly) so reused sequence values stay unique across periods.

Scopes

A scope is an arbitrary string that isolates counters: typically a company, tenant or branch id. acme and globex each get their own INV-2026-00001.

When you configure a scope column on a model ($documentNumberScopeColumn), that attribute must be set before saving. A missing value throws a LogicException rather than silently falling back to the global scope, which would otherwise mix one tenant's numbers into another's sequence.

Usage

Via the facade

Has the sequence been used yet?

hasEverAllocated() answers "has this sequence ever consumed a number?" across every period, which is what you need before letting someone change a numbering setting: the pattern, the reset policy or gap_free of a type, or the table and connection the counters live in.

peek() cannot answer it. It only looks at the current period, so under a yearly reset a sequence used all through last year reads as untouched on 1 January:

Two details worth knowing:

An unknown document type throws rather than returning false, so a typo cannot silently report an unused sequence. See below.

Configuration errors

next(), peek() and hasEverAllocated() all resolve the type's configuration before doing anything else, so each of the three can throw:

Exception Raised when
UnknownDocumentType the type is absent from numbering.types
InvalidPattern the type's pattern uses a token the compiler does not know

Both report a configuration the package cannot work with, and neither is recoverable where it is raised: the fix is in config/numbering.php or in the type name the caller passed, not in the calling code path.

Every exception the package raises extends Vimatech\DocumentNumbering\Exceptions\NumberingException, and that is the type to catch if you want one, as a last-resort guard around the whole operation, not as flow control. Note that it also covers the allocation-time failures SequenceLocked and SequenceUnreadable, which next() can raise long after the configuration has been accepted.

Via the Eloquent trait

Add HasDocumentNumber to a model and tell it which type and scope to use. The number is assigned automatically on creating.

You can replace the property hooks with method overrides for full control:

For gap-free types the trait wraps the first save() in a database transaction, so the number allocation and the row INSERT commit together: if the insert fails, the number is released back into the sequence.

Complete Example

Concurrency & gap-free guarantees

Each (scope, type, period_key) owns one row in document_number_sequences. Allocation runs inside a transaction and takes a lockForUpdate() lock on that row, so concurrent callers serialise on the row rather than racing the counter, on engines that implement row locks; see Database notes. The first allocation for a new period inserts the row at 0; the unique index on (scope, type, period_key) makes a lost insert race harmless.

gap_free: true (no gaps, default)

The number is allocated inside the caller's transaction. The row lock is held until that transaction commits, so:

The cost is contention: the lock is held for the lifetime of the surrounding transaction, so keep those transactions short.

When using the facade directly, wrap your write and the allocation together:

The HasDocumentNumber trait does this wrapping for you.

gap_free: false (fast sequential)

The number is committed as soon as it is allocated and is not returned on a later rollback, so gaps are possible. Choose this for sequences that may skip values (e.g. internal quote drafts), where throughput matters more than a perfectly dense sequence.

FrankenPHP / Laravel Octane (worker mode)

The package is safe under long-lived worker runtimes (FrankenPHP worker mode, Octane with Swoole/RoadRunner), where the application is booted once and reused across many requests. Specifically:

No special configuration is required. If you register an event listener for NumberAllocated, follow the usual Octane guidance and avoid capturing request-scoped state in long-lived listeners.

Database notes

What the test suite establishes, and what it does not. Allocation goes through Laravel's query builder and contains no engine-specific SQL, so the same code path runs on all three. What differs is the guarantee underneath it, and the automated suite exercises only one of them: it runs on SQLite, where lockForUpdate() compiles to an empty string and the serialisation observed (including the no-gaps, no-duplicates concurrency test) comes from SQLite's database-wide write lock. The SELECT ... FOR UPDATE path that MySQL and PostgreSQL take is not covered by any test in this repository. Treat the row lock on those engines as designed-for and unproven here rather than verified, and see CONTRIBUTING for why a second connection holding the row does not close that gap.

If the database aborts a statement while waiting for the lock (lock-wait timeout or deadlock), a Vimatech\DocumentNumbering\Exceptions\SequenceLocked exception is thrown and the transaction is rolled back: no number is consumed.

Events

Vimatech\DocumentNumbering\Events\NumberAllocated is dispatched after each allocation:

For gap-free types this fires inside the caller's transaction, so a rollback also discards anything a listener did transactionally.

Testing

The suite includes a concurrency test that forks multiple worker processes against a shared SQLite database and asserts that the allocated numbers contain no duplicates and no gaps.

Design Principles

Contributing

Contributions are welcome.

Please ensure:

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our Security Policy for reporting vulnerabilities.

License

The MIT License (MIT). Please see License File for more information.

Credits

Built and maintained by Vimatech. Created by Adel Zemzemi, Laravel SaaS architect.


All versions of laravel-document-numbering with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^11.0 || ^12.0 || ^13.0
illuminate/database Version ^11.0 || ^12.0 || ^13.0
illuminate/support Version ^11.0 || ^12.0 || ^13.0
nesbot/carbon Version ^2.72 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package vimatech/laravel-document-numbering contains the following files

Loading the files please wait ...