38

Is solution for this in Eloquent ORM?

I have array with parents idetifiers:

Array ( [0] => 87,  [1] => 65, ... )

And i want select table PRODUCTS where parent_id column = any id in array

Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
Lajdák Marek
  • 2,969
  • 8
  • 29
  • 58

2 Answers2

80

Fluent:

DB::table('PRODUCTS')->whereIn('parent_id', $parent_ids)->get();

Eloquent:

Product::whereIn('parent_id', $parent_ids)->get();
rmobis
  • 26,129
  • 8
  • 64
  • 65
Dwight
  • 12,120
  • 6
  • 51
  • 64
  • 2
    FWIW, also in the Eloquent example you need to `get()` the results: `Product::whereIn('parent_id', $parent_ids)->get();` – Ludder Sep 25 '13 at 20:01
24

Your array must be like this :

$array = array(87, 65, "etc");
Product::whereIn('parent_id', $array)->get();

or

Product::whereIn('parent_id', array(87, 65, "etc"))->get();
ElGato
  • 511
  • 1
  • 5
  • 11