有了以下代码,我想根据单位选择所有预订
$unitsQuery = DB::table('units as u')
->leftJoin('reservations as r', function ($join) use($fromDate,$toDate) {
$join->on('u.id', '=', 'r.unit_id')
->where('r.team_id', auth()->user()->current_team_id)
->where('r.date_in ', '>=' , $fromDate)
->where('r.date_out ', '<=' , $toDate)
->whereNull('r.checked_out')
->whereNull('r.deleted_at')
->where('date_out', '!=', $fromDate)
->where('r.status' , '!=' , 'canceled')
->leftJoin('customer as c','r.customer_id' , '=' ,'c.id')
->leftJoin('wallets as w', function ($join) {
$join->on('r.id', '=', 'w.holder_id')
->where('w.holder_type' , 'App\Reservation');
});
})
->select('u.id as uid',
'u.name as uname',
'u.team_id as utid',
'u.unit_number as unum',
'u.status as ustatus',
'u.sunday_day_price as sunday_price',
'u.monday_day_price as monday_price',
'u.tuesday_day_price as tuesday_price',
'u.wednesday_day_price as wednesday_price',
'u.thursday_day_price as thursday_price',
'u.friday_day_price as friday_price',
'u.saturday_day_price as saturday_price',
'u.month_price as month_price',
)
->where('u.team_id' , auth()->user()->current_team_id)
->where('u.enabled' , 1)
->whereNull('u.deleted_at')
->orderBy('u.unit_number' , 'asc')
->groupBy(['u.id'])
->get();
我想要实现的是根据 $fromDate 和 $toDate 获取我的所有房间以及该房间下的所有预订,如何在一个选择中实现这一点以获得类似的结果
{
"u.id":1,
"reservations":[
{
"id":1,
"price":200
},
{
"id":2,
"price":500
}
]
},
守候你守候我