Laravel 4 Eloquent ORM 选择 where - 数组作为参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17605693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:33:07 来源:igfitidea点击:
Laravel 4 Eloquent ORM select where - array as parameter
提问by Lajdák Marek
Is solution for this in Eloquent ORM?
在 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
我想要选择表 PRODUCTS,其中 parent_id 列 = 数组中的任何 id
回答by Dwight
Fluent:
流利:
DB::table('PRODUCTS')->whereIn('parent_id', $parent_ids)->get();
Eloquent:
雄辩:
Product::whereIn('parent_id', $parent_ids)->get();
回答by ElGato
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();