shiftechafrica / shift-code-generator
此包根据年份、日期和月份生成代码。例如,它使用 A - Z 字母表示月份。
v1.5.0
2023-02-24 16:08 UTC
Requires
- illuminate/support: ^5.8|^6.0|^7.0|^8.0|^9.0|^10
- webpatser/laravel-uuid: ^3.0|^4.0
README
介绍
此包根据年份、日期和月份生成代码。例如,它使用 A - Z 字母表示月份。例如 1E1NKJDQVW 代码 1 代表年份数,E 代表月份,1 代表日期,而 NKJDQVW 是一个随机字符串。此库模仿了 mpesa-transaction-id。
安装
推荐通过 Composer 安装 shift-code-generator。
# Install package via composer
composer require shiftechafrica/shift-code-generator
然后,运行 Composer 命令以安装最新稳定版本的 shiftechafrica/shift-code-generator
# Update package via composer
composer update shiftechafrica/shift-code-generator --lock
安装后,包将自动发现,但如果需要,您可以运行
# run for auto discovery <-- If the package is not detected automatically -->
composer dump-autoload
然后运行此命令,以获取您自己的配置的 config/shift-code-generator.php
# run this to get the configuration file at config/shift-code-generator.php <-- read through it --> php artisan vendor:publish --provider="ShiftechAfrica\CodeGenerator\ShiftCodeGeneratorServiceProvider"
将创建一个 config/shift-code-generator.php 文件,因此如果您想使用数据库,请按照下一步说明如何初始化。以下内容添加到您的 .env 文件中。
YEAR_OF_START=2020 #pass the year that your application is launched USE_DATABASE=false #pass true if you want to use the database and false to use your default YEAR_OF_START
您需要在 database/seeds/DatabaseSeeder 中添加此内容。为了确保我们初始化一些数据以设置将用于生成代码的默认日期
/** * Seed the application's database. * * @return void */ public function run() { // other seeds... $this->call(\ShiftechAfrica\CodeGenerator\Seeds\ShiftCodeGeneratorFactory::class); }
用法
请按照以下步骤了解如何使用 shift-code-generator
如何使用库
如何生成代码...
use ShiftechAfrica\CodeGenerator\ShiftCodeGenerator; /** * ---------------------------- * Generate the code here * ----------------------------------------------------------------------- * Code will be generated in the format of Y-M-D + 7 random characters * ----------------------------------------------------------------------- * @return string */ public function generateCode() { return (new ShiftCodeGenerator())->generate();// in the generate method you can pass an int value like 5,4 or any to get the length of the code you want }
版本说明
安全漏洞
对于任何安全漏洞,请通过电子邮件联系 Shiftech Africa。
许可
此包是开源的,许可协议为 MIT 许可证。