Ad

Laravel Multiple Wherein's

How can I do multiple wherein in laravel?

$devices = DB::table('foo')
              ->select('foo.*')
              ->whereIn('bar1', $request->bar1)
              ->whereIn('bar2', $request->bar2)
              ->get();

Above is my sample code but it is returning me an empty array.

Ad

Answer

It is ok to use multiple WHERE IN constraints in your query. The code you provided is also ok.

If you're getting no results, make sure that values of $request->bar1 and $request->bar2 are what you expect - they should be arrays of values that contain what you want your bar1/bar2 columns to be.

You can always get the generated SQL by calling toSql() instead of get(), you can also inspect the values of parameters by calling getBindings().

Ad
source: stackoverflow.com
Ad