tfsthiagobr98 / laravel-naming-series
Generate Custom Ids for your models
Fund package maintenance!
TFSThiagoBR98
Requires
- php: ^8.3
- illuminate/contracts: ^11.0||^12.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^3.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.6
- orchestra/testbench: ^10.0
- pestphp/pest: ^3.7
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2025-03-02 21:21:35 UTC
README
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Installation
You can install the package via composer:
composer require tfsthiagobr98/laravel-naming-series
You can publish and run the migrations with:
php artisan vendor:publish --tag="laravel-naming-series-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="laravel-naming-series-config"
This is the contents of the published config file:
return [ 'database' => [ 'connection' => null, 'table' => 'naming_series', ], 'split_with' => '.', 'initial_increment' => 1000, ];
Usage
use TFSThiagoBR98\LaravelNamingSeries\Contracts\HasNamingSeries; use TFSThiagoBR98\LaravelNamingSeries\Concerns\UsingNamingSeries; class Contract extends Model implements HasNamingSeries { use UsingNamingSeries; /** * Indicates if the model uses unique ids. * * @var bool */ public $usesUniqueIds = true; /** * Field => Format list for model fields * * @var array<string,string> */ public static function getSerieList(): array { return [ 'code' => 'CNT-.YY.MM.####', ]; } /** * Get the columns that should receive a unique identifier. * * @return array */ public function uniqueIds() { return [ 'code' => 'getSeriesField', // your series field ]; }
Avaliable Aliases
The Serie format must be splited in part with .
character. For example:
CNT-.YY.MM.####
where: CNT-
is a literal string, YY
and MM
is a variable and ####
is the sequential number.
#
: Numeric Sequence ()YY
: Year (2 Digits)YYYY
: Year (4 Digits)MM
: MonthMM
: DayWW
: ISO Week CountTS
: Timestamp (Miliseconds)TL
: Timestamp (Seconds)
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
License
The MIT License (MIT). Please see License File for more information.