I am trying to retrieve the hotel list, In which rooms available for requested dates.
The room availability table looks like below.
room_availability
id | hotel | room | start_date | end_date | count |
--------------------------------------------------------------------
1 | 301 | 121 | 2019-04-01 | 2019-04-01 | 10 |
2 | 301 | 121 | 2019-04-02 | 2019-04-02 | 7 |
3 | 301 | 121 | 2019-04-03 | 2019-04-03 | 4 |
4 | 301 | 120 | 2019-04-02 | 2019-04-02 | 5 |
5 | 301 | 120 | 2019-04-03 | 2019-04-03 | 6 |
And the search model code as,
$no_of_days = (Carbon::parse($data['start_date'])
->diffInDays(Carbon::parse($data['end_date'])));
$no_of_days += 1;
$hotelList = $this
->select('id','hotel_code','room', \DB::Raw('count(hotel_code) as total_days'))
->with(['hotel:id,name,logo,location,code'])
->where('start_date','>=',$data['start_date'])
->Where('start_date','<=',$data['end_date'])
->groupBy('hotel_code')
->having('total_days',$no_of_days)->get();
For the request (2019-04-02 - 2019-04-03) without having condition,
->having('total_days',$no_of_days)
returns hotel 301 but when It is added empty set returned.
What I have to add or remove?