【发布时间】:2018-09-24 17:45:21
【问题描述】:
我有一系列收藏。在收藏中我有关系。我如何在这些关系中使用whereIn?
$arrayCollections = $category->products;
$arrayCollections = $arrayCollections->character->whereIn('id', [1,2,3,4]); //I need use whereIn in character relation. I get error: Property [character] does not exist on this collection instance.
foreach($arrayCollections as $product) {
.... //but in foreach I can use $product->character
}
产品型号关系::
public function character()
{
return $this->hasMany('App\Models\ProductCharacter');
}
【问题讨论】:
-
$arrayCollections中有什么内容? -
显示你的数据库表和定义字符的位置
-
character- 模型产品关系 -
您是否尝试过
dd($arrayCollections)来查看character是否在集合中? -
@kerbholz 不,在
arrayCollections我得到数组。是的,我的收藏中有character