0
使用Laravel,我在访问我的其他表格时遇到了一些麻烦,这些表格都是多对多的。雄辩多对多
所以基本上,我开始了与用户ID和希望列出的客户,用户拥有。
public function customers()
{
return $this->belongsToMany('Customer', 'user_to_customer');
}
这工作,承担我的用户id为1:
User::find(1)->customers;
但是现在我想说的是,对于这些客户,列出他们的产品。但是这需要在相同的结果内。
我想我会需要客户模型内的东西,如:
public function products()
{
return $this->belongsToMany('Product', 'user_to_customer');
}
我似乎无法工作,如何在同一查询中访问此?例如:
User::find(1)->customers->products;
不确定..有什么建议吗?
啊,谢谢,我从来没有真正理解渴望在此之前加载。作品款待,欢呼:) – Alias