oobook / manage-eloquent
管理 Laravel Eloquent 模型关系、表列和列类型
v1.0.2
2024-09-27 14:28 UTC
Requires
- php: ^8.0|^8.1|^8.2|^8.3
Requires (Dev)
- doctrine/dbal: ^3.9
- jeroen-g/laravel-packager: ^2.10
- orchestra/testbench: ^7.0|^8.23.4|^9.0
- phpunit/phpunit: ^9.0|^10.0.7|^11.0
README
此包将帮助您管理 Laravel Eloquent 模型关系、表列和列类型。
安装
您可以通过 composer 安装此包
composer require oobook/manage-eloquent
用法
为了使用 definedRelationships() 方法,您必须定义关系返回类型,例如 \Illuminate\Database\Eloquent\Relations\BelongsTo,如下所示。
<?php namespace App\Models; use Oobook\Database\Eloquent\Concerns\ManageEloquent; class Product extends Model { use ManageEloquent; protected $fillable = [ 'name' ]; public function tags(): \Illuminate\Database\Eloquent\Relations\MorphToMany { return $this->morphToMany( Tag::class, 'taggable' ); } public function category(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Category::class); } }
示例
<?php $product = new Product(); // RELATIONSHIPS // get all defined Relationships $product->definedRelationships(); // ['tags', 'category'] // get relationships by relationship type $product->definedRelations('BelongsTo'), // ['category']; $product->definedRelations(['BelongsTo', 'MorphToMany']), // ['tags', 'category']; // get relation types $product->definedRelationsTypes(), // [ // "category" => "BelongsTo" // "tags" => "MorphToMany" // ] $product->hasRelation('tags') // true; $product->getRelationType('tags') // \Illuminate\Database\Eloquent\Relations\MorphToMany; // COLUMNS $product->hasColumn('name') // true if exists on db table; $product->getColumns() // get the list of columns of the table; // get the list of timestamp columns of the table; $product->getTimestampColumns()
测试
composer test
更新日志
有关最近更改的更多信息,请参阅 更新日志。
贡献
有关详细信息,请参阅 贡献指南。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 oguz.bukcuoglu@gmail.com 联系我们,而不是使用问题跟踪器。
致谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。
Laravel 包模板
此包是使用 Laravel 包模板 生成的。