Hey @farshadf
Modify it to your needs but something like that will do the trick:
$room_capacity = Capacity::query()
->whereBetween('date', [
Carbon::now()->startOfMonth()->subMonth()->toDateString(),
Carbon::now()->startOfMonth()->subMonth()->endOfMonth()->toDateString(),
])
->get();
This here makes no sense:
->whereDate('from_date', '<=', $dates[$t])
It actually should be:
->where('date', '<=', $dates[$t])
Also if you try to do a booking system then try to think in a smallest possible interval when you think about your reservations. For instance if room can only be booked for 1 day, then instead of creating from_date to_date you could create 31 days in a given month and then create lets say 4 consecutive bookings for one day for that room - meaning it would be booked for 4 days.
This type of approach will make your system more flexible and easier to work with.
You can even go down to hours and book rooms per hours. Even go down to minutes etc etc. Your future queries would be much simpler then as well.
Hope it helps!