laravel - Access Method in a hasManyThorugh
问题描述
I have 4 tables,
props, listing, offers, contact
props has many listing, listing belongs to props
public function listings() { return $this->hasMany('App\Models\Listing\Listing'); }
offer belongs to listing,
public function property()
{
return $this->belongsTo('App\Models\Property\Property')->with('owners');
}
then offer belongsToMany contact trough offer_contact table
public function buyers()
{
return $this->belongsToMany(Contact::class, 'offer_contact', 'offer_id', 'contact_id')->with('primary_email');
}
My question is, how to access buyers()?
Something like $props->buyers()
In props model, what I did is
return $this->hasManyThrough('App\Models\Offer\Offer', 'App\Models\Listing\Listing');
解决方案
你不能。您可以使用嵌套迭代来获取属性,列表属于每个属性,优惠属于每个列表,然后是属于该优惠的客户。
或者,您可以使用原始查询来获得所需的结果DB::statement();
推荐阅读
- amazon-web-services - 使用 JavaScript 开发工具包 --no-include-email 标志的 AWS ECR 登录
- javascript - toUpperCase 不起作用
- yaml - CircleCi 2.0 工作流程需要选项不起作用
- javascript - JQUERY 中的 $(window).load 未触发
- django - 为通过 imagefield django 上传的图像提供唯一名称
- java - 在 Spring 应用程序中设置时区
- php - 用 Wordpress 替换 href 中的“.html”
- c# - 双击 Wpf c# 选择列表框的元素
- c# - 返回始终为空起订量
- common-lisp - 常见的 lisp 和中缀包