【发布时间】:2019-09-04 01:18:03
【问题描述】:
我在这里有一个酒店模型、一个房间模型和一个房间价格模型我想通过我的嵌套关系查询以找到最便宜的房间,所以我必须获取今天房间的所有价格,然后对它们进行排序,从中选出最低的每个房间,然后为我的结果选择最低的房间:
在我的模型关系中,我选择每个房间所有价格中的最低价格:
// this will bring me the lowest price for the room in the day
public function roomPricingHistorySearch()
{
return $this->hasOne(roomprices::class,'room_id','id')->orderBy('sales_price','ASC');
}
这里我想在所有房间中选择最低的
$data = Hotel::with([
'rooms.roomprices' => function ($query) {
//here i want to pick the lowest price room of all.
$query->Where('is_deleted', '1');
}
]);
【问题讨论】:
-
roomprices 查询的排序依据在哪里? (后一个查询)?另外,
$query->where...,没有大写字母