2016-06-26 20 views
1

Wie kann ich Abfrage-Generator verwenden, um whereNotIn zu einer anderen Tabelle zu konditionieren, ohne DB :: raw();Laravel DB Query Builder "WhereNotIn" zu einer anderen Tabelle

$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; 
+2

möglich Duplikat http://stackoverflow.com/questions/16815551/how-to-do-this-in-laravel-subquery-where-in – herrjeh42

+0

Ihr Modell Codes –

+0

@ herrjeh42 Dank Sende es half. –

Antwort

0

Ich löste dadurch.

$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; 
Verwandte Themen