mll-lab / laravel-utils
MLL 共享的 Laravel 工具
v6.0.0
2024-09-17 11:42 UTC
Requires
- php: ^8.1
- illuminate/support: ^9.51 || ^10 || ^11
- mll-lab/php-utils: ^1.13 || ^2 || ^3 || ^4 || ^5
- mll-lab/str_putcsv: ^1
- ramsey/uuid: ^4.7
- thecodingmachine/safe: ^1 || ^2
Requires (Dev)
- doctrine/dbal: ^3.6
- ergebnis/composer-normalize: ^2
- jangregor/phpstan-prophecy: ^1
- jbzoo/mermaid-php: ^2.3
- larastan/larastan: ^2
- laravel/framework: ^9 || ^10 || ^11
- mll-lab/graphql-php-scalars: ^4 || ^5
- mll-lab/php-cs-fixer-config: ^5
- mll-lab/rector-config: ^2
- orchestra/testbench: ^7.7 || ^8 || ^9
- phpstan/extension-installer: ^1
- phpstan/phpstan-deprecation-rules: ^1
- phpstan/phpstan-phpunit: ^1
- phpstan/phpstan-strict-rules: ^1
- phpunit/phpunit: ^9 || ^10 || ^11
- thecodingmachine/phpstan-safe-rule: ^1.2
Suggests
- jbzoo/mermaid-php: Used for visualization of the transition graph of the model states
This package is auto-updated.
Last update: 2024-09-17 11:42:55 UTC
README
MLL 共享的 Laravel 工具
安装
通过 composer 安装
composer require mll-lab/laravel-utils
使用方法
参见 测试。
自增
允许在不实际使用自增的情况下创建自增 ID。
扩展类 Autoincrement
并为您的 ID 起一个描述性的名字。
use MLL\LaravelUtils\Database\Autoincrement; final class MaxFooId extends Autoincrement { public static function name(): string { return 'max_foo_id'; } }
生成迁移并调用其中的 createTable()
方法
public function up() { MaxFooId::createTable(); }
要在模型中使用此 ID,将 $incrementing
设置为 false 并在 booted()
方法中将 ID 赋值给模型
public $incrementing = false; protected static function booted(): void { self::creating(function (self $instance): void { $instance->id ??= MaxFooId::next(); });
条件迁移
要条件性地运行迁移,实现 MLL\LaravelUtils\Database\ConditionalMigration
接口及其 ->shouldRun()
方法
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; } };
严格占位符
为了使您的占位符持续更新为该包的最新版本,请将 /stubs
添加到您的 .gitignore
文件中,并将以下内容添加到您的 composer.json
文件中
"scripts": {
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
+ "@php artisan vendor:publish --tag=strict-stubs --force"
]
}
变更日志
参见 CHANGELOG.md
。
贡献
参见 CONTRIBUTING.md
。
许可证
本软件包采用 MIT 许可证授权。