PHPackages                             ameax/sequence-number - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ameax/sequence-number

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ameax/sequence-number
=====================

A laravel package to configure and generate sequence numbers for invoices

1264↓33.3%1[3 PRs](https://github.com/ameax/sequence-number/pulls)PHPCI passing

Since May 12Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/ameax/sequence-number)[ Packagist](https://packagist.org/packages/ameax/sequence-number)[ RSS](/packages/ameax-sequence-number/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

SequenceNumber Package Documentation
====================================

[](#sequencenumber-package-documentation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/062e0c5f2262c4b5cb1fd880ea6666b534920bbdab635173e79bd50fc3bd6872/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d6561782f73657175656e63652d6e756d6265722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ameax/sequence-number)
[![GitHub Tests Action Status](https://camo.githubusercontent.com/7d01214e0f18621a1a774e38009d63e7538dd32f942b9c71a99eb730e653df6e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616d6561782f73657175656e63652d6e756d6265722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/ameax/sequence-number/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://camo.githubusercontent.com/a38b67aad888c15c617d61a6ba6574b87b25261d6afa31d136dbb33c4c3d53e3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616d6561782f73657175656e63652d6e756d6265722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/ameax/sequence-number/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)
[![Total Downloads](https://camo.githubusercontent.com/e9540aac046efc11cac9d95f3c7541b93d15b0be5dff74b862b231652229a556/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d6561782f73657175656e63652d6e756d6265722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ameax/sequence-number)

The **SequenceNumber** package provides an easy-to-use service for generating customizable sequence numbers. This is useful for generating unique identifiers such as invoice numbers, order IDs, or other sequences that follow a defined format.

---

Features
--------

[](#features)

- Supports customizable prefixes, suffixes, and number lengths.
- Configurable yearly resets.
- Supports check digits for validation.
- Format sequences with custom separators and year formats.
- Includes robust database-backed sequence tracking.
- Configurable default database connection for models.

---

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require ameax/sequence-number
```

Publish and run the migrations:

```
php artisan vendor:publish --tag="sequence-number-migrations"
php artisan migrate
```

Optionally, publish the configuration file:

```
php artisan vendor:publish --tag="sequence-number-config"
```

---

Configuration
-------------

[](#configuration)

The configuration file allows you to customize the behavior of the package. Below is the content of the `config/sequence-number.php` file:

```
return [
    'connection' => null, // Set the default connection of the Models
];
```

### Explanation:

[](#explanation)

- **`connection`**: Defines the database connection to use for the `sequences` and `sequence_counters` models. If set to `null`, the default Laravel connection will be used. Set this to a specific connection name if your sequences should use a dedicated database.

#### Example:

[](#example)

```
return [
    'connection' => 'tenant', // Use the tenant database connection
];
```

---

Models and Fields
-----------------

[](#models-and-fields)

### **`Sequence` Model**

[](#sequence-model)

The `sequences` table stores the configuration for each sequence.

FieldTypeDescription`id``bigInteger`Primary key of the sequence configuration.`token``string`Unique identifier for the sequence.`prefix``string`Optional prefix to prepend to the sequence number.`suffix``string`Optional suffix to append to the sequence number.`number_min_length``unsignedSmallInteger`Minimum length of the sequence number, padded with leading zeros if needed.`year_format``enum`Format of the year (`none`, `2-digits`, `4-digits`).`year_separator``enum`Separator to place after the year (e.g., `-`, `/`, `.`).`use_check_digit``boolean`Whether to include a check digit for validation.`check_digit_separator``enum`Separator for the check digit.`check_digit_position``enum`Position of the check digit (`prefix`, `suffix`).`reset_yearly``boolean`Whether to reset the sequence yearly.`start_value``unsignedInteger`Starting value for the sequence.`payload``json`Additional metadata for the sequence.`created_at``timestamp`Timestamp when the sequence was created.`updated_at``timestamp`Timestamp when the sequence was last updated.### **`SequenceCounter` Model**

[](#sequencecounter-model)

The `sequence_counters` table tracks the current value of a sequence.

FieldTypeDescription`id``bigInteger`Primary key of the sequence counter.`sequence_id``foreignId`Foreign key referencing the `sequences` table.`current_value``integer`The current value of the sequence.`year``integer`The year of the last reset for the sequence.`created_at``timestamp`Timestamp when the counter was created.`updated_at``timestamp`Timestamp when the counter was last updated.---

Usage
-----

[](#usage)

### Generating a Sequence Number

[](#generating-a-sequence-number)

1. **Initialize the SequenceService**Use the `SequenceService::make()` method to create a service instance.
2. **Load a Sequence by Token**Use the `byToken(string $token)` method to load a sequence by its unique token.
3. **Generate the Next Sequence Number**Call `next()` to generate the next sequence number based on the configuration.

#### Using Sequence Service:

[](#using-sequence-service)

```
use Ameax\SequenceNumber\Services\SequenceService;

$sequenceService = SequenceService::make()->byToken('invoice');
$nextSequence = $sequenceService->next();

echo $nextSequence; // Example: INV2023.001
```

#### Using Sequence Model:

[](#using-sequence-model)

```
$sequence = Sequence::where('token', 'invoice')->first();

echo  $sequence->next();
```

### Validating a Sequence Number

[](#validating-a-sequence-number)

Use the `validateSequenceNumber(string $sequenceNumber)` method to validate a sequence number with a check digit.

#### Example:

[](#example-1)

```
$isValid = SequenceService::make()->byToken('invoice')->validateSequenceNumber('INV2023.001');
echo $isValid ? 'Valid' : 'Invalid';
```

---

Configuration Examples
----------------------

[](#configuration-examples)

### Sequence Configuration Example

[](#sequence-configuration-example)

Create a sequence configuration in the `sequences` table:

```
use Ameax\SequenceNumber\Models\Sequence;

$sequence = Sequence::create([
    'token' => 'invoice',
    'prefix' => 'INV',
    'number_min_length' => 3,
    'year_format' => '4-digits',
    'year_separator' => '.',
    'use_check_digit' => true,
    'check_digit_position' => 'suffix',
    'reset_yearly' => true,
    'start_value' => 1,
]);
```

---

Testing
-------

[](#testing)

### Example Test Scenarios

[](#example-test-scenarios)

```
use Ameax\SequenceNumber\Models\Sequence;
use Ameax\SequenceNumber\Services\SequenceService;

// Create a sequence configuration
$sequence = Sequence::create([
    'token' => 'invoice',
    'prefix' => 'INV',
    'number_min_length' => 3,
]);

// Generate the first sequence number
expect(SequenceService::make()->byToken('invoice')->next())->toBe('INV001');

// Add a year format and separator
$sequence->update([
    'year_format' => '4-digits',
    'year_separator' => '-',
]);
expect(SequenceService::make()->byToken('invoice')->next())->toBe('INV2023-002');
```

### Running Tests

[](#running-tests)

Run all tests using Pest or PHPUnit:

```
composer test
```

---

Changelog
---------

[](#changelog)

Refer to the [CHANGELOG](CHANGELOG.md) for details on recent changes.

---

Contributing
------------

[](#contributing)

Contributions are welcome! Please see the [CONTRIBUTING](CONTRIBUTING.md) file for guidelines.

---

License
-------

[](#license)

The MIT License (MIT). Please see the [LICENSE](LICENSE.md) file for more details.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance58

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f67be86f330b5a3e644c8594bbf322be6ab1a08da5434d9cef417097d5567287?d=identicon)[aranes](/maintainers/aranes)

---

Top Contributors

[![ms-aranes](https://avatars.githubusercontent.com/u/69188126?v=4)](https://github.com/ms-aranes "ms-aranes (10 commits)")[![raymadrona](https://avatars.githubusercontent.com/u/4514908?v=4)](https://github.com/raymadrona "raymadrona (6 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")

### Embed Badge

![Health badge](/badges/ameax-sequence-number/health.svg)

```
[![Health](https://phpackages.com/badges/ameax-sequence-number/health.svg)](https://phpackages.com/packages/ameax-sequence-number)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
