Laravel 5.4 in the subquery, where is the condition?

I want to write an additional query inside, where in the condition and in the subquery there were conditions, checking the parent field of the request.

in the following way,

$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, user.id does not take from the parent request. If I specify the number manually, then it works correctly.

What is wrong with my request .. can you suggest.

+5
source share
1 answer

use whereRaw , not 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); }); 
+1
source

Source: https://habr.com/ru/post/1269712/


All Articles