I have a Hotel model which has Many Rooms that can be occupied. How should I query this:
Hotel list
- the count of Rooms
- the count of Occupied Rooms
The query:
$hotels = Hotel::where('foo',$bar) ->withCount('rooms') ->withCount(['rooms' => function ($query) { $query->where('status', 'Occupied'); }]) ->get(); The result:
$hotel->rooms_count gives the count of occupied rooms, which is the last withCount expression.
What I'm trying to get
$hotel->rooms_countas the count of rooms in each hotel$hotel->occupied_rooms_countas the count of occupied rooms of each hotel
as an alias of the second withcount:
Is there a way to alias the second withCount on Room?