雄辩在哪里不查询?

c4p*_*one 3 eloquent laravel-4

我正在尝试用eloquent构建以下sql查询.该查询为我提供了table_a中所有记录,这些记录位于id列表中,不会出现在table_b中.

select * from table_a 
where id in (1,2,3)
   and id not in 
      (select tablea_id from table_b 
       where tablea_id in (1,2,3))
Run Code Online (Sandbox Code Playgroud)

那么我该如何做到雄辩呢?我想避免使用原始查询.

//does not work
TableA::whereIn('id',$ids)
   ->whereNotIn('id', TableB::select('tabla_id')->whereIn($ids));
Run Code Online (Sandbox Code Playgroud)

luk*_*ter 10

要运行子查询,您必须传递一个闭包:

TableA::whereIn('id',$ids)
      ->whereNotIn('id', function($q){
          $q->select('tabla_id')
            ->from('tableb');
            // more where conditions
      })
      ->get();
Run Code Online (Sandbox Code Playgroud)