gpt4 book ai didi

php - Laravel whereIn 数组

转载 作者:行者123 更新时间:2023-12-03 21:22:17 25 4
gpt4 key购买 nike

我有一系列的收藏。在收藏中我有关系。我如何使用 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');
}

最佳答案

尝试这个:

$characters = $category->products()->character()->whereIn('id', [1,2,3,4])->get();

foreach($characters as $character) {
// $character
}

关于php - Laravel whereIn 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52474370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com