Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 807
Lajdák Marek Avatar asked Jul 12 '13 00:07

Lajdák Marek


2 Answers

Fluent:

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

Eloquent:

Product::whereIn('parent_id', $parent_ids)->get(); 
like image 90
Dwight Avatar answered Oct 27 '22 16:10

Dwight


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();
like image 29
ElGato Avatar answered Oct 27 '22 16:10

ElGato