marjose123 / laravel-numberizer
Laravel package to create autonumber for Eloquent model
Requires
- laravel/framework: ^8.0|^9.0|^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.20
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
This package is auto-updated.
Last update: 2024-11-08 03:10:58 UTC
README
Introduction
Laravel-Numberizer
is a fork of laravel-autonumber with a support of latest laravel version.
Installation
You can install the package via composer:
composer require marjose123/laravel-numberizer
You can publish and run the migrations with:
php artisan vendor:publish --tag="numberizer-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="numberizer-config"
This is the contents of the published config file:
return [ /* * '?' will be replaced with the increment number. */ 'placeholder' => '?', /* * The number of digits in the autonumber */ 'length' => (int) 6, /* * The Starting Value you want to start the creation of the incremental number */ 'startingValue' => (int) 11111 ];
Usage
- Add the
AutoNumber
contracts and add also to your model theHasNumberizer
concerns.
use \MarJose123\LaravelNumberizer\Contracts\AutoNumber; use \MarJose123\LaravelNumberizer\Concerns\HasNumberizer; class Purchase extends Model implements AutoNumber { use HasNumberizer; /** * Return the autonumber configuration array for this model. * * @return array */ public function getAutoNumberOptions() { return [ 'purchase_number' => [ 'format' => 'PO-?', // autonumber format. '?' will be replaced with the generated number. 'length' => 5 // The number of digits in an autonumber ] ]; } }
- If you want to use
closure
on your format you do so.
public function getAutoNumberOptions() { return [ 'purchase_number' => [ 'format' => function () { return 'PO-' . \Carbon\Carbon::today()->year . '-?'; // autonumber format. '?' will be replaced with the generated number. }, 'length' => 6 // The number of digits in the autonumber ] ]; }
The purchase_number
will be automatically generated based on the format given when saving the Purchase model.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
Thank you!
- laravel-autonumber - For beautiful plugin.
License
The MIT License (MIT). Please see License File for more information.