首页 > 解决方案 > 如何使或未定义?

问题描述

我是 Php 的新手,我陷入了困境。

我需要制作一个类别过滤器,它是用一个复选框选中的。orWhere如何为每个类别做?

我需要类似的东西:

$users = DB::table('users')
                 -> where ('category_id', 1)
                 -> orWhere ('category_id', 2)
                ...
                -> orWhere ('category_id', n)
                 -> get ();

标签: phpdatabaselaravel

解决方案


你应该使用whereIn

$users = DB::table('users')
              ->whereIn("category_id" , [1,2,...,n])
              ->get();

推荐阅读