我在 laravel eloquent ORM 中编写查询时遇到问题 .
laravel eloquent ORM
我的疑问是
SELECT book_name,dt_of_pub,pub_lang,no_page,book_price FROM book_mast WHERE book_price NOT IN (100,200);
现在我想将此查询转换为laravel eloquent .
您也可以按以下方式使用 WhereNotIn :
ModelName::whereNotIn('book_price', [100,200])->get(['field_name1','field_name2']);
这将返回带有特定字段的 Record 的集合
whereNotIn方法验证给定列的值是否包含在给定数组中:
$users = DB::table('users') ->whereNotIn('id', [1, 2, 3]) ->get();
实现whereNotIn的动态方式:
$users = User::where('status',0)->get(); foreach ($users as $user) { $data[] = $user->id; } $available = User::orderBy('name', 'DEC')->whereNotIn('id', $data)->get();
查询生成器:
DB::table(..)->select(..)->whereNotIn('book_price', [100,200])->get();
雄辩:
SomeModel::select(..)->whereNotIn('book_price', [100,200])->get();
4 回答
您也可以按以下方式使用 WhereNotIn :
这将返回带有特定字段的 Record 的集合
whereNotIn方法验证给定列的值是否包含在给定数组中:
实现whereNotIn的动态方式:
查询生成器:
雄辩: