php - Laravel with eager loading using condition -


i'm trying optimize relationship using eager loading , implement conditions in clause eager loading, when 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 following:

'select * `enquiries` `staff_id` in (10, 15) , `ed_timestamp` >= '2017-09-12'; 

it seems ignoring conditionals in clause. there way fix or implement properly?

thanks

wherehas() works same has() allows specify additional filters related model check.

$totalopenqry =  enquiry::wherein('staff_id', $employeeids)         ->with('enquirystats')         ->wherehas('enquirystats', function ($query) {             $query->where('is_open','=',true)                 ->where('is_dead','=',false)                 ->orderby('id','asc');         })         ->where('ed_timestamp', '>=', $daterange['start'])         ->with('country'); //  enquirystats have is_open = true , is_dead = false returned 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -