phpinnacle/sequentia

Scoped and date-aware sequence numbers for Laravel applications.

Maintainers

Package info

github.com/phpinnacle/sequentia

pkg:composer/phpinnacle/sequentia

Transparency log

Statistics

Installs: 9

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-09-01 10:02 UTC

This package is auto-updated.

Last update: 2026-09-01 15:41:50 UTC


README

Sequentia generates scoped, bucketed and date-aware sequence numbers for Laravel models. Counter updates use an atomic database upsert and can be isolated by tenant, model scope, bucket and time period.

Installation

composer require phpinnacle/sequentia
php artisan phpinnacle-sequentia:install

For manual installation:

php artisan vendor:publish --tag="phpinnacle-sequentia-config"
php artisan vendor:publish --tag="phpinnacle-sequentia-migrations"
php artisan migrate

Registering counters

Register watched Eloquent models from an application service provider:

use App\Models\Order;
use PHPinnacle\Sequentia\SequenceWatcher;

SequenceWatcher::register(Order::class, scheme: ['issuer_type', 'issuer_id']);

Every created model increments annual, yearly and monthly counters. Bucketed counters are isolated by the configured scheme; global counters ignore it. Pass a model attribute name as tenant to isolate counters by tenant.

Formatting numbers

use PHPinnacle\Sequentia\Sequence;

$number = Sequence::create(
    pattern: 'ORD-[DD][MM][YY]-[SY]',
    scope: Order::class,
    bucket: ['issuer_type' => 'company', 'issuer_id' => 10],
)->forTenant($tenantId)->get();

Available counters are SA, SY, SM, GA, GY and GM: scoped/global counters for all time, year and month. Date placeholders are D, DD, M, MM, Y, YY and W. Additional context may be passed to get().

Rebuild registered counters from existing records when necessary:

php artisan sequentia:rebuild

Configuration

Set connection in phpinnacle-sequentia.php to store counters on a dedicated database connection. The current atomic upsert implementation requires PostgreSQL.

License

The MIT License (MIT). See License File.