soap/laravel-running-numbers
Composer 安装命令:
composer require soap/laravel-running-numbers
包简介
This is my package laravel-running-numbers
README 文档
README
The package provides a class to generate running number, keep track of them in database table. One running number type can have many prefix to generate running number. Generated running numbers was not stored in database, just keep last number for each prefix. You can reset it to specified value for each prefix. If specified type and prefix does not exists in the database, it will be create and assign number to 1.
Support us
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require soap/laravel-running-numbers
You can publish and run the migrations with:
php artisan vendor:publish --tag="running-numbers-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="running-numbers-config"
This is the contents of the published config file:
return [ 'table_prefix' => '', ];
Usage
Using RunningNumber class to generate running number is deprecated. Now I introduced RunningNumberGenerator class instead.
This is for version less than 0.0.6.
RunningNumber::generate('STUDENT_CODE', '672', 3); // 673001 RunningNumber::generate('STUDENT_CODE', '672', 3); // 673002 // Reset specified type and prefix to some value RunningNumber::reset('STUDENT_CODE', '672', 0); RunningNumber::generate('STUDENT_CODE', '672', 3); // 673001 RunningNumber::delete('STUDENT_CODE', '672');
This is from my implementation.
namespace App\Observers; use App\Models\Student; use App\Models\EducationLevel; use Soap\Laravel\RunningNumbers\RunningNumber; class StudentObserver { /** * Handle the Student "creating" event. * * @return void */ public function creating(Student $student) { if (empty($student->student_code)) { $level = EducationLevel::find($student->education_level_id)->level; $prefix = ($student->registered_at->year + 543) % 100 . $level; $student->student_code = RunningNumber::generate('STUDENT_CODE', $prefix, 3); } } }
For verison 0.0.6 and above;
Using RunningNumberGenerator to generate and reset value.
RunningNumberGenerator::make()
->type('STUDENT_CODE')->prefix("672")->generate();
If type was not provided, 'Default' will be used. If prefix was not provided, date("Y") will be used.
Set Running number format
Availabe token are {TYPE}, {PREFIX}, {NUMBER}. These information will be keep tracked in database record.
RunningNumberGenerator::make()
->type('STUDENT_CODE')->prefix("672")->format("{PREFIX}-{NUMBER}")->generate();
Reset running number to specified value.
Zero value if no value passed. Call generate(), running number will be increased by one and saved to database.
RunningNumberGenerator::make()
->type('STUDENT_CODE')->prefix("672")->->format("{PREFIX}-{NUMBER}")->reset()->generate();
// return 672-001
RunningNumberGenerator::make()
->type('STUDENT_CODE')->prefix("672")->->format("{PREFIX}-{NUMBER}")->reset(1)->generate();
// return 672-002
Set length of padding number.
If not set length of 3 will be used.
RunningNumberGenerator::make()
->type('STUDENT_CODE')->prefix("672")->->format("{PREFIX}-{NUMBER}")->length(4)->reset()->generate();
// return 672-0001
Artisan Command
List
Usage: runningnumber:list [<type> [<prefix>]] Arguments: type Type of running number prefix Prefix before running number
Generate
Usage: runningnumber:generate [options] [--] <type> <prefix> Arguments: type Type of running number prefix Prefix before running number
Reset
Usage:
runningnumber:reset [options] [--] <type> <prefix>
Arguments:
type Type of running number
prefix Prefix before running number
Options:
--value[=VALUE] Value to reset running number to [default: "1"]
Delele
Usage: runningnumber:delete <type> <prefix> Arguments: type Type of running number prefix Prefix before running number
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.
soap/laravel-running-numbers 适用场景与选型建议
soap/laravel-running-numbers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.59k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「prasit gebsaap」 「laravel-running-numbers」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 soap/laravel-running-numbers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 soap/laravel-running-numbers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 soap/laravel-running-numbers 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Make Omise payment gateway integration easier with Laravel
Provides Laravel workflow guards using Symfony expression and related objects
This is my package laravel-omise-webhooks
Laravel shopping cart with conditions and coupons support
Time zone list and helpers for Laravel application
Thai provinces database for Laravel application
统计信息
- 总下载量: 3.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-25