哪里有没有按预期工作
问题描述:
我想获得所有Shop
s有$item_ids = array('1', '17');
之一。哪里有没有按预期工作
但是,下面的代码没有按照我的预期那样做 - 它只是给我所有的商店。
$shops = Shop::whereHas('items', function($query) use ($item_ids) {
$query->where('items.id', '=', $item_ids[0]);
foreach(array_slice($item_ids, 1) as $item_id) {
$query->orWhere('items.id', '=', $item_id);
}
})
->get(array('shops.id', 'shops.shop_name', 'shops.lat', 'shops.lng'));
我做,我只与指定Item
S的一个获得Shop
S'
答
你还是使用:
$shops = Shop::whereHas('items', function($query) use ($item_ids) {
$query->whereIn('id', $items_ids);
})->get();
或
$shops = Shop::whereHas('items', function($query) use ($item_ids) {
$query->whereIn('id', $items_ids);
})->select('shops.id', 'shops.shop_name', 'shops.lat', 'shops.lng')->get();