jarrodtomholt / belongs-to-macro
使用简单的宏自动为迁移中的 foreignIdFor 实体添加索引和约束
1.0.0
2023-02-14 20:08 UTC
Requires
- php: ^8.0
- illuminate/support: ^8.0|^9.0|^10
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
README
自动为迁移添加索引和外键约束,强制执行数据完整性,保持引用关联,并提高查询性能。
安装
您可以通过 composer 安装此包
composer require jarrodtomholt/belongs-to-macro
用法
在迁移的 up()
方法中,使用以下代码替换 foreignIdFor
以添加索引和外键约束。
Schema::create('posts', function (Blueprint $table) { $table->belongsTo(User::class); }); // will expand to $table->foreignIdFor(User::class)->index()->constrained();
需要可空字段?使用 belongsToOrNull
Schema::create('posts', function (Blueprint $table) { $table->belongsToOrNull(User::class); }); // will expand to $table->foreignIdFor(User::class)->nullable()->index()->constrained();
测试
composer test
贡献
请参阅 CONTRIBUTING 以获取详细信息。
安全
如果您发现任何与安全相关的问题,请使用问题跟踪器提出问题。
许可证
MIT 许可证(MIT)。请参阅 许可证文件 以获取更多信息。
Laravel 包模板
此包是使用 Laravel 包模板 生成的。