Haven't tried it but something like this should work for you.
DB::table('obmains')
->leftJoin('employeelogs', 'obmains.ob_code', '=', 'employeelogs.obcode')
->leftJoin('users', function ($join) {
$join->on('employeelogs.emp_id', '=', 'users.id')
->whereNotIn('obmains.ob_code', DB::table('employeelogs')
->whereIn('emp_id', DB::table('users')
->where(function ($query) {
$query->where('approver', 1)
->orWhere('super_approver', 1);
})
->where('department', 4)
->pluck('id')
)
->pluck('obcode')
);
})
->select('obmains.*')
->get();
LOL WTF I SOLVE IT But the result of this query and the query above is put it in array, converting this query to eloquent is impossible, array and model is very different ANSWER TO MY QUESTION: IMPOSSIBLE TO CONVERT TO ELOQUENT
$obmain = DB::table('obmains')
->leftJoin('employeelogs', 'obmains.ob_code', '=', 'employeelogs.obcode')
->leftJoin('users', 'employeelogs.emp_id','=','users.id')
->whereNotIn('obmains.ob_code',
(DB::table('employeelogs')
->whereIn('emp_id',
(DB::table('users')
->where('approver', 1)
->orWhere(function ($query) {
$query->where('super_approver', 1)
->where('department', Auth::user()->department);
})
->select('id'))
)
->select('obcode'))
)
->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community