marjose123/laravel-numberizer
最新稳定版本:1.0.2
Composer 安装命令:
composer require marjose123/laravel-numberizer
包简介
Laravel package to create autonumber for Eloquent model
README 文档
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
AutoNumbercontracts and add also to your model theHasNumberizerconcerns.
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
closureon 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.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-13