I am working with the fullcalendar plugin and I am trying to fetch all the events in my database after and before a certain date. Full calendar paginates the events by adding paramaters called 'start' and 'end'. I am able to parse these in to Carbon instances like so:
Carbon::parse($data['start']);
Carbon::parse($data['end']);
Now this is working fine:
$events = $this->event->where('user_id', auth()->user()->id)
->get();
But this is not:
$events = $this->event->where('user_id', auth()->user()->id)
->where('start', '>=', Carbon::parse($data['start']))
->where('end', '<=', Carbon::parse($data['end']))
->get();
Why am I not getting events published between these two dates with the second approach. When I run the first approach, it works fine and fetches all the events and publishes them on the current page but unfortunately it is also fetching a whole lot of events that don't need fetching.
After listening to the DB queries, the event query was like:
select * from
events
whereuser_id
= ? andstart
>= ? andend
<= ?