I want to write sub query inside where in condition and in subquery were condition, checking with parent query field.
as follows,
$query = DB::table('users');
$query->whereNotIn('users.id', function($query) use ($request) {
            $query->select('award_user.user_id')
                    ->from('award_user')
                    ->where('award_user.user_id', 'users.id')
                    ->where('award_user.award_id', $request->award_id);
        });
Query is working fine, but
 ->where('award_user.user_id', 'users.id')
This line, users.id is not taking from parent query. If I enter manually number, then it is working correctly.
What is wrong with my query.. can you please suggest.
use whereRaw rather than where
$query = DB::table('users');
$query->whereNotIn('users.id', function($query) use ($request) {
            $query->select('award_user.user_id')
                    ->from('award_user')
                    ->whereRaw('award_user.user_id', 'users.id')
                    ->whereRaw('award_user.award_id = '.$request->award_id);
        });
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With