【发布时间】:2020-08-18 23:42:09
【问题描述】:
我有 File 模型来存储我的图像,并且我有 shop 模型,商店可以有许多图像,并且在商店模型中我编写了以下代码:
public function Files()
{
return $this->hasMany('system\models\file', 'attachment_id');
}
我想用它的图像检索商店模型,现在我的问题是如何将 where 条件放在相关的位置。我的检索商店模型的代码是:
$shop = Shop::where('id', $id)->with('ShopType', 'User', 'Files')->get();
注意:我需要为在 Files 方法中设置的主题之一调用 attachment_id 的关系设置 2 个条件,而我的第二个条件是 attachment_type
请帮我。谢谢
【问题讨论】:
标签: laravel model relation data-retrieval wherehas