Download the PHP package devaspid/laravel-id-generator without Composer

On this page you can find all versions of the php package devaspid/laravel-id-generator. 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-id-generator

Laravel ID Generator

Generate business document numbers such as invoices, transactions, procurement records, and purchase orders without scanning their transaction tables.

The package keeps only mutable counter state in id_sequences; formatting and reset behaviour remain version-controlled in config/id-generator.php. Counters are incremented inside a database transaction with a row lock, making the generator safe for concurrent requests.

Try Demo

Click

Features

Requirements

Installation

Install the package:

Publish its configuration and migration, then migrate:

Define your generators in config/id-generator.php, then create their state rows:

Run id-generator:sync on every environment after adding a generator. It creates missing rows only; it never resets or overwrites an existing counter.

Configuration

Option Required Default Description
prefix No '' Text before the sequence number.
suffix No '' Text after the sequence number.
padding No 0 Minimum number width, padded on the left with zeroes.
scope No never Counter lifecycle: never, yearly, monthly, or daily.

Supported placeholders in prefix and suffix are {Y}, {m}, {d}, and {His}. For example, INV-{Y}{m}- becomes INV-202607- in July 2026.

Placeholder Output Description
{Y} 2026 Four digit year
{y} 26 Two digit year
{F} July Full month name
{M} Jul Short month name
{m} 07 Month with leading zero
{n} 7 Month without leading zero
{l} Monday Full day name
{D} Mon Short day name
{d} 09 Day with leading zero
{j} 9 Day without leading zero
{H} 14 Hour
{i} 35 Minute
{s} 22 Second
{His} 143522 HHMMSS

Usage

Configure your generator in config/id-generator.php.

Generate the next document number.

Output:

Using with Eloquent Model Events

A common approach is generating the document number automatically when a model is created.

Generating Different Document Types

Every configured generator is referenced by its configuration key.

Using Inside a Database Transaction

When a document number should only exist if the business transaction succeeds, generate it inside the same database transaction.

Manual Generation

You can generate a document number anywhere in your application.

Using the Auto Discovered Alias

Laravel automatically registers the facade alias, allowing the shorter syntax.

Example Configuration

Generated values:

Scope and reset behaviour

Reset behaviour is driven by a scope, not a scheduler and not the date of the last invoice. The database stores current and last_scope in one row for each generator.

For a monthly invoice generator, a July state might be current = 1523 and last_scope = '2026-07'. The first generation in August detects the new scope while holding the row lock, changes the state to current = 0 and last_scope = '2026-08', then increments to 1. No business table is scanned, and no extra sequence rows are created for idle periods.

never resolves to a global scope and never resets. yearly, monthly, and daily resolve respectively to YYYY, YYYY-MM, and YYYY-MM-DD.

Concurrency

generate() starts a database transaction, locks the single row for the requested generator (SELECT ... FOR UPDATE), evaluates its scope, increments the counter, and saves it before committing. Concurrent requests for the same generator wait briefly for that row instead of receiving the same number. Different generators use different rows and can proceed independently.

Use a unique database index on your document-number column as a final application-level integrity safeguard.

API reference

Throws InvalidGeneratorConfiguration if the generator is absent or invalid, and SequenceNotFound if id-generator:sync has not created its state row.

Upgrade guide

Before upgrading this package, commit your composer.lock, application config, and database backup. Run Composer's update, review the package release notes, then run:

The command is safe to rerun and preserves current and last_scope. Do not truncate id_sequences in a live system unless restarting every document sequence is intentional.

FAQ

Why not scan the invoice table for its highest number?

Scanning grows more expensive as the table grows and has a race condition: two concurrent requests can read the same maximum. This package locks one small state row instead.

Does monthly reset require a scheduler?

No. The first generation in a new period resets atomically. Months with no documents create no data and require no work.

Will a failed transaction leave a number gap?

When generate() runs inside the same outer transaction as the document insert, a rollback rolls back both changes. Database engines and other application workflows may still create gaps in some circumstances; document sequences should generally be unique and ordered, not assumed gapless.

Can I add custom scopes?

The ScopeResolverRegistry is intentionally separated from the manager so a future release can expose custom resolver registration without changing storage or generation semantics.

License

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

Support the Project

If you find this project useful, consider giving it a ⭐ on GitHub.

Maintained with ❤️ by devASPId.

🌐 https://asp.web.id

🤝 https://asp.web.id/volunteer


All versions of laravel-id-generator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.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 devaspid/laravel-id-generator contains the following files

Loading the files please wait ...