I have a query to return: All schedules that doesn’t have program or all schedules that have at least a program but the program is yet to end.
The issue is that, the query returns all schedules that doesn’t have a program and also all schedules that have a program where the program has ended.
Below is my code:
Schedule::where(['owner_id' => auth()->user()->owner->id,
'session_id' => CurrentSession::fetchCurrentSession()->session_id
])
->whereDoesntHave('program', function(Builder $query){
$query->where('end_date', null);
})
->orderBy('schedule_time', 'asc')
->get();`
2
Answers
Why no just simply use
whereHas('program')
instead?If you’re looking for a
Schedule
with noprogram
relationship or aSchedule
with aprogram
that has a nullend_date
then you should specify that or in your query.