Question : When we have booking date (start date to end date) in db booking table and need to search from “from date” to ” to date” by search box for available seats.
booking table :
id | name | start_date | end_date |
1 | a | 23-06-2017 | 29-06-2017 |
here we need 4 condition to check to do not get in between those dates
Example : Search date can be those
1. 24-06-2017 to 25-06-2017
2. 22-06-2017 to 30-06-2017
3. 22-06-2017 to 24-06-2017
4. 25-06-2017 to 31-06-2017
Now Laravel Query :
$booking_arr = DB::table(‘booking’)
->whereRaw(“((booking.start_date <= ‘”.$start_date.”‘ AND booking.end_date > ‘”.$start_date.”‘) OR (booking.start_date < ‘”.$end_date.”‘ AND booking.end_date >= ‘”.$end_date.”‘) OR (booking.start_date >= ‘”.$start_date.”‘ AND booking.start_date <= ‘”.$end_date.”‘))”)
->where(‘booking.campsite_id’,$input[‘campsite_id’])
->whereIn(‘category_campsite_id’, $campsites_categories)
->get();