Laravel DB Query Builder“whereNotIn”到另一个表

时间:2016-06-26 08:37:54

标签: database laravel

如何使用查询构建器来调整whereNotIn到另一个表而不使用DB :: raw();

plt.figure(1)
plt.subplot(211)
plt.plot('''Data''')

plt.subplot(212)
plt.plot('''Data''')
plt.draw()

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。

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