cleaniquecoders/laravel-running-number

Generate running number when creating new records in your table.

Fund package maintenance!
cleaniquecoders

Installs: 12 242

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 2

Open Issues: 0

pkg:composer/cleaniquecoders/laravel-running-number

3.0.0 2025-11-13 10:53 UTC

This package is auto-updated.

Last update: 2025-11-13 11:05:24 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status PHPStan Analysis Total Downloads

Generate sequential running numbers for your Laravel application. Perfect for invoice numbers, order numbers, customer IDs, and any other sequential identifiers you need.

โœจ Features

  • ๐Ÿ”ข Sequential Generation - Automatic sequential number generation per type
  • ๐Ÿ’พ Database Persistence - Reliable state storage in your database
  • ๐Ÿ”„ Reset Periods - Automatic reset (daily, monthly, yearly, or never)
  • ๐Ÿ”’ Thread-Safe - Race condition protection with database transactions
  • ๐Ÿข Multiple Sequences - Separate sequences per type using scopes
  • ๐ŸŽฏ Custom Starting Numbers - Start sequences from any number
  • ๐Ÿ“Š Range Management - Set maximum limits with exception handling
  • ๐Ÿ“… Date-Based Formats - Built-in date presenters for time-organized numbers
  • ๐Ÿ‘๏ธ Preview Mode - Preview next numbers without incrementing
  • ๐Ÿ“ฆ Bulk Generation - Generate multiple numbers at once atomically
  • โš™๏ธ Configurable - Customize padding, formatting, and behavior
  • ๐Ÿ†” UUID Support - Built-in UUID support for running number records
  • ๐Ÿท๏ธ Native PHP Enums - Modern PHP 8.1+ enum support with Traitify
  • ๐Ÿ”ง Extensible - Custom generators and presenters via contracts
  • ๐Ÿš€ Developer Friendly - Helper functions, facades, Eloquent trait, Artisan commands, and REST API
  • ๐ŸŽญ Event System - Built-in events for auditing and notifications
  • ๐ŸŒ REST API - Optional HTTP endpoints for remote number generation
  • ๐Ÿ“ฆ Wide Compatibility - Laravel 9-12 & PHP 8.1-8.4

๐Ÿ“ฆ Installation

Install via Composer:

composer require cleaniquecoders/laravel-running-number

Publish and run migrations:

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

Optionally, publish the configuration:

php artisan vendor:publish --tag="running-number-config"

๐Ÿ“– Detailed Guide: See the complete Installation Guide for more information.

๐Ÿš€ Quick Start

Basic Usage

use CleaniqueCoders\RunningNumber\Enums\Organization;

// Using the helper function
$number = running_number()
    ->type(Organization::PROFILE->value)
    ->generate();
// Output: PROFILE001

In Model Events

use Illuminate\Database\Eloquent\Model;

class Invoice extends Model
{
    protected static function booted()
    {
        static::creating(function ($invoice) {
            $invoice->invoice_number = running_number()
                ->type('invoice')
                ->generate();
        });
    }
}

// Now every invoice automatically gets a sequential number
$invoice = Invoice::create([
    'customer_id' => 1,
    'amount' => 100.00,
]);
// invoice_number: INVOICE001

Custom Formatting

use CleaniqueCoders\RunningNumber\Contracts\Presenter;

class CustomPresenter implements Presenter
{
    public function format(string $type, int $number): string
    {
        return sprintf('%s-%04d', $type, $number);
    }
}

$number = running_number()
    ->type('invoice')
    ->formatter(new CustomPresenter())
    ->generate();
// Output: INVOICE-0001

๐Ÿ“– Learn More: Check out the Quick Start Guide and Common Scenarios for more examples.

๐Ÿ“š Documentation

Comprehensive documentation is available in the docs directory:

  • Getting Started - Installation, quick start, and core concepts
  • Configuration - Configuration options, types, enums, and models
  • Usage - Helper functions, facades, model integration, and examples
  • Advanced Features - Date formats, scopes, ranges, and more
  • Development - Testing, contributing, and development setup

Quick Links

๐Ÿงช Testing

composer test

See the Testing Guide for more information.

๐Ÿ“ Changelog

Please see CHANGELOG for more information on what has changed recently.

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

๐Ÿ”’ Security

Please review our security policy on how to report security vulnerabilities.

๐Ÿ™ Credits

๐Ÿ“„ License

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