通过查询laravel中同一列的多个数据,使用查询构建器获取数据

时间:2019-12-11 10:01:34

标签: sql laravel

DB::table('products')
->where('status', '=', 'published')
->where('sub_category', '=', 'grooming-wellness')
->where('sub_category', '=', 'beauty-care')
->get();

它不起作用。它返回0个数据。

1 个答案:

答案 0 :(得分:4)

我假设您要检查某个字段是否具有特定值或另一个值。您可以使用whereIn来实现:

DB::table('products')
    ->where('status', '=', 'published')
    ->whereIn('sub_category', ['grooming-wellness', 'beauty-care'])
    ->get();

Laravel 6.x Docs - Query Builder - Where Clauses - Additional Where Clauses whereIn