【发布时间】:2017-03-16 23:03:48
【问题描述】:
我正在尝试对 laravel 雄辩的嵌套关系施加计数约束,但它没有按预期工作。
这里的场景是:获取在日期范围内有空房的酒店
$hotels = Hotel::where('destination_id', $destinationId) - > with(['rooms' = > function ($query) use($totalNights, $check_in, $check_out) { $查询 - > 与([ 'dateWisePricing' = > 函数 ($dateWisePricing) 使用($check_in, $check_out) { $dateWisePricing -> where('date', '>=', $check_in); $dateWisePricing -> where('date', '<', $check_out); $dateWisePricing - > orderBy('date'); } ]); $query -> has('dateWisePricing', '>=', $totalNights); } ]) - > has('rooms.dateWisePricing') - > get();这里返回的房间在日期范围内不可用(即 dateWisepricing im empty collection)
请帮忙
【问题讨论】: