2

How i can use query builder to condition whereNotIn to an other table without using DB::raw();

$query ="select * from project 
            where prj_usr_id= $user->id 
            and now()<prj_expiry 
            and prj_id not in(select bd_prj_id from bid where bd_status=1) 
            and prj_status='open' 
            order by prj_updated_date desc;
Cœur
  • 37,241
  • 25
  • 195
  • 267
Shahid Chaudhary
  • 890
  • 3
  • 14
  • 25

1 Answers1

0

I solved by this.

$results = DB::table('project')
                        ->where('prj_usr_id',  '=' , 1 ) 
                        ->where('prj_status',  '=' , 'open' ) 
                        ->where('prj_expiry',  '<' , Carbon::Now() ) 
                        ->whereNotIn ('prj_id',function ($query)
                        {
                            $query->select(DB::raw(1))
                                    ->from('bid')
                                    ->where('bd_status',  '=' , '1' ) 
                                    ->get(['bd_prj_id']); 
                        })
                        ->orderBy('prj_updated_date', 'desc') 
                        ->paginate(5);
return  $results; 
Shahid Chaudhary
  • 890
  • 3
  • 14
  • 25