定制 marjose123/laravel-numberizer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

marjose123/laravel-numberizer

最新稳定版本:1.0.2

Composer 安装命令:

composer require marjose123/laravel-numberizer

包简介

Laravel package to create autonumber for Eloquent model

README 文档

README

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

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

  1. Add the AutoNumber contracts and add also to your model the HasNumberizer 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
            ]
        ];
    }

}
  1. 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!

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-13