我有麻烦写在laravel雄辩的ORM查询。

我的问题是

SELECT book_name,dt_of_pub,pub_lang,no_page,book_price  
FROM book_mast        
WHERE book_price NOT IN (100,200);

现在我想把这个问题转换成laravel雄辩。


当前回答

可以通过以下方式使用WhereNotIn:

$category=DB::table('category')
          ->whereNotIn('category_id',[14 ,15])
          ->get();`enter code here`

其他回答

或者试着在laravel里拔一下 在这里

DB::table('user')                 
          ->select('id','name')
          ->whereNotIn('id', DB::table('curses')->where('id_user', '=', $id)->pluck('user_id'))
          ->get();  

查询构建器:

DB::table(..)->select(..)->whereNotIn('book_price', [100,200])->get();

口才:

SomeModel::select(..)->whereNotIn('book_price', [100,200])->get();

你也可以用下面的方式使用WhereNotIn:

ModelName::whereNotIn('book_price', [100,200])->get(['field_name1','field_name2']);

这将返回具有特定字段的Record集合

你可以照着做。

DB::table('book_mast') 
->selectRaw('book_name,dt_of_pub,pub_lang,no_page,book_price')  
->whereNotIn('book_price',[100,200]);

这是Laravel 7的工作变体

DB::table('user')                 
  ->select('id','name')
  ->whereNotIn('id', DB::table('curses')->where('id_user', $id)->pluck('id_user')->toArray())
  ->get();