Generate running number when creating new records in your table.
cleaniquecoders/laravel-running-number is a Laravel package for generate running number when creating new records in your table..
It currently has 4 GitHub stars and 16.836 downloads on Packagist (latest version 3.1.0).
Install it with composer require cleaniquecoders/laravel-running-number.
Discover more Laravel packages by cleaniquecoders
or browse all Laravel packages to compare alternatives.
Last updated
Generate sequential running numbers for your Laravel application. Perfect for invoice numbers, order numbers, customer IDs, and any other sequential identifiers you need.
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.
use CleaniqueCoders\RunningNumber\Enums\Organization;
// Using the helper function
$number = running_number()
->type(Organization::PROFILE->value)
->generate();
// Output: PROFILE001
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
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.
Comprehensive documentation is available in the docs directory:
composer test
See the Testing Guide for more information.
Please see CHANGELOG for more information on what has changed recently.
We welcome contributions! Please see our Contributing Guide for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.