在我的laravel项目中,我有经理表和资金表。
经理-> id,姓名,钱包基金-> id,->,fundable_type,fundable_id,receivable_type,receivable_id,status
我在经理模型中有以下关系
public function funds()
{
return $this->morphMany(Fund::class, 'fundable');
}
public function receiveds()
{
return $this->morphMany(Fund::class, 'receivable');
}我在基金模型中有以下关系
public function fundable()
{
return $this->morphTo();
}
public function receivable()
{
return $this->morphTo();
}基金经理->基金正在很好地推广基金模式。
我想接待那些收到基金经理的经理。
我试过美元经理-->资金-->应收款项,但它不起作用。
发布于 2022-01-07 02:09:40
在关系规范中,您可以附加其他模型的关系:
public function funds()
{
return $this->morphMany(Fund::class, 'fundable')->with('receivable');
}发布于 2022-01-07 14:17:54
好吧,我自己找到答案了。
public function managers()
{
return $this->hasManyThrough(Manager::class, Fund::class, 'fundable_id', 'id', 'id', 'receivable_id')
->where('fundable_type', Manager::class)->where('receivable_type', Manager::class)->distinct();
}https://stackoverflow.com/questions/70614524
复制相似问题