I have the information of events in database which have (events title, from_date, to_date)
events from_date to_date
events 1 2018-10-12 2018-10-16
events 2 2018-10-15 2018-10-19
events 3 2018-10-11 2018-10-17
And this is my search by specific date function
$from_date = Carbon::parse(request('from_date'))->endOfDay();
$events = Events::where('from_date', '<=' ,$from_date)
->where('to_date', '>=' ,$from_date)
->get();
return $events;
My route for this API is day-search. so when i input api/day-search?from_date=my input. When i input the 2018-10-15, it should be shown all 3 events occur during the 2018-10-15.
Is there anyway to improve the accuracy of this code? Thank you.