mll-lab/laravel-utils
Composer 安装命令:
composer require mll-lab/laravel-utils
包简介
Shared Laravel utilities of MLL
README 文档
README
Shared Laravel utilities of MLL
Installation
Install through composer
composer require mll-lab/laravel-utils
Usage
See tests.
Autoincrement
Allows the creation of incrementing IDs without actually using autoincrement.
Extend the class Autoincrement with a descriptive name for your ID.
use MLL\LaravelUtils\Database\Autoincrement; final class MaxFooID extends Autoincrement { public static function name(): string { return 'max_foo_id'; } }
Generate a migration and call the createTable() method in it:
public function up(): void { MaxFooID::createTable(); }
To use this ID in your model, set $incrementing to false and assign the ID to your model in the booted() method:
public $incrementing = false; protected static function booted(): void { self::creating(function (self $instance): void { $instance->id ??= MaxFooID::next(); });
Conditional Migrations
To run a migration conditionally, implement the MLL\LaravelUtils\Database\ConditionalMigration
interface and its ->shouldRun() method in your migration:
use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Carbon; use MLL\LaravelUtils\Database\ConditionalMigration return new class extends Migration implements ConditionalMigration { public function up(): void { // Something that would put intense strain on the database } public function shouldRun(): bool { $currentHour = Carbon::now()->hour; // Only run between 01:00 and 03:00 return $currentHour > 1 && $currentHour < 3; } };
Strict Stubs
To continually keep your stubs updated with the latest and greatest from this package,
add /stubs to your .gitignore and add the following to your composer.json:
"scripts": {
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
+ "@php artisan vendor:publish --tag=strict-stubs --force"
]
}
Changelog
See CHANGELOG.md.
Contributing
See CONTRIBUTING.md.
License
This package is licensed using the MIT License.
mll-lab/laravel-utils 适用场景与选型建议
mll-lab/laravel-utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 189.1k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 12 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mll-lab/laravel-utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mll-lab/laravel-utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 189.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-05