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
Requires
- php: ^8.1 | ^8.2 | ^8.3 | ^8.4
- cleaniquecoders/traitify: ^1.2.1
- illuminate/contracts: ^9.0 | ^10.0 | ^11.0 | ^12.0
- spatie/laravel-package-tools: ^1.14
Requires (Dev)
- laravel/framework: 12.*
- laravel/pint: ^1.6
- nunomaduro/collision: ^7.0|^8.0
- orchestra/testbench: 10.*
- pestphp/pest: ^2.0|^3.0
- pestphp/pest-plugin-laravel: ^2.0|^3.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.10|^2.0
- phpstan/phpstan-deprecation-rules: ^1.0|^2.0
- phpstan/phpstan-phpunit: ^1.0|^2.0
- phpunit/phpunit: ^9.5|^10.0|^11.0
- spatie/laravel-ray: ^1.26
README
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
- Installation Guide
- Quick Start
- Common Scenarios
- Date-Based Formats
- Multiple Sequences
- Custom Starting Numbers
- Number Range Management
- Preview & Bulk Generation
- Upgrade Guide
- API Reference
๐งช 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.