I'm trying to optimize a relationship using eager loading and implement conditions in the with clause for eager loading, however when I do the below:
$totalOpenQry = Enquiry::whereIn('staff_id', $employeeIds)
->with(['enquiryStats' => function ($query) {
$query->where('is_open','=',true)
->where('is_dead','=',false)
->orderBy('id','asc');
}])
->where('ed_timestamp', '>=', $dateRange['start'])
->with('country');
$totalOpen = $totalOpenQry->toSql();
$totalOpenQry->toSql()
produces the following:
'select * from `enquiries` where `staff_id` in (10, 15) and `ed_timestamp` >= '2017-09-12';
It seems to be ignoring the where conditionals in my with clause. Is there a way to fix this or implement it properly?
Thanks