【问题标题】:Laravel 4 Eloquent ORM select where - array as parameterLaravel 4 Eloquent ORM 选择 where - array 作为参数
【发布时间】:2013-07-10 10:50:42
【问题描述】:

在 Eloquent ORM 中有解决方案吗?

我有一个带有父母标识符的数组:

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

我想选择表 PRODUCTS,其中 parent_id 列 = 数组中的任何 id

【问题讨论】:

    标签: laravel laravel-4 eloquent


    【解决方案1】:

    流利:

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

    雄辩:

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

    【讨论】:

    • FWIW,同样在 Eloquent 示例中您需要 get() 结果:Product::whereIn('parent_id', $parent_ids)->get();
    【解决方案2】:

    你的数组必须是这样的:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-09
      • 2014-08-19
      • 2016-06-13
      • 1970-01-01
      • 2015-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多