I have a big query which has a nested query. I want to know how to write it so that it's not cluttered. What I tried was creating query objects
//get the latest joined employee per department
$q1 = Employee::where('job', 'assistant')
->groupBy('dept_id')
->select(DB::raw('MAX(empid) as empid'));
//fetch his course ID
$q2 = Employee::whereIn('empid', function($query){
$query->$q1;
})
->where('university', 'LIKE', '%UCLA%')
->select('course_id')
->distinct()
->get()->lists('course_id');
I am getting this error
[Symfony\Component\Debug\Exception\FatalThrowableError]
Cannot access empty property
How should I do it?