我有File模型来存储我的图像,而我有shop模型,这家商店可以有很多图像,在商店模型中,我编写了此代码:
public function Files()
{
return $this->hasMany('system\models\file', 'attachment_id');
}
并且我想用它的图像来检索商店模型,现在我的问题是如何将条件置于相关位置。我用于检索商店模型的代码是:
$shop = Shop::where('id', $id)->with('ShopType', 'User', 'Files')->get();
note:我需要为关系设置两个条件,即在Files方法中调用attachment_id的主题集之一,第二个条件是attachment_type请帮我。谢谢
我有这个为我工作
// USER model
public function orders()
{
return $this->hasMany(Order::class, 'user_id');
}
// Controller
user->orders()->where('id', $id);