New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

tfsthiagobr98/laravel-naming-series

Generate Custom Ids for your models
1,033
Install
composer require tfsthiagobr98/laravel-naming-series
Latest Version:2.1.0
PHP:^8.3
Laravel:11 · 12
Older releases:10
License:MIT
Last Updated:Mar 2, 2025
Links: GitHub  ·  Packagist
Maintainer: tfsthiagobr98

Generate Custom Ids for your models

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

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: Month
  • MM: Day
  • WW: ISO Week Count
  • TS: 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.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

660,512,042 9,702
laravel/framework

The Laravel Framework.

617,629,957 34,997
laravel/tinker

Powerful REPL for the Laravel framework.

524,145,802 7,444
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

442,489,569 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

418,503,470 4,663

Version History

Version Released PHP Laravel License
2.1.0 ^8.3 ^11.0||^12.0 MIT
2.0.0 ^8.3 ^11.0 MIT
1.0.0 ^8.1 ^10.0 MIT