toanld/multi-relationships
最新稳定版本:v1.1.3
Composer 安装命令:
composer require toanld/multi-relationships
包简介
Compoships offers the ability to specify relationships based on two (or more) columns in Laravel's Eloquent ORM. The need to match multiple columns in the definition of an Eloquent relationship often arises when working with third party or pre existing schema/database.
README 文档
README
Require this package with composer. It is recommended to only require the package for development.
composer require toanld/multi-relationships
Syntax
namespace App; use Illuminate\Database\Eloquent\Model; use Toanld\Relationship\MultiRelationships; class Test extends Model { use MultiRelationships; public function category(){ //list_cat can be json ids (example: [2,3,43,23]) or string list ids (example: 2,3,43,23) return $this->hasOne(Category::class,'id',['cat_3','cat_2','cat_1','list_cat']); } }
Example
$data = Test::with(['category:id,name'])->limit(2)->get(); foreach ($data as $row){ //return model category relate with field cat_1 $category = $row->getRelationshipValue($row->cat_1,'category'); }
统计信息
- 总下载量: 289
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2022-08-31