Lajdák Marek
Lajdák Marek

Reputation: 3079

Laravel 4 Eloquent ORM select where - array as parameter

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

Upvotes: 38

Views: 55921

Answers (2)

ElGato
ElGato

Reputation: 511

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();

Upvotes: 24

Dwight
Dwight

Reputation: 12470

Fluent:

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

Eloquent:

Product::whereIn('parent_id', $parent_ids)->get();

Upvotes: 80

Related Questions