whereBetween传递数组

时间:2018-02-06 07:44:09

标签: laravel eloquent laravel-5.2 laravel-query-builder

您好我有查询要将数组传递给whereBetween查询。

例如我有一个看起来像这样的数组

Array
(
    [product_id] => Array
        (
            [0] => 31337
            [1] => 31366
        )

    [lands] => Array
        (
            [0] => 12
            [1] => 23
        )

)

现在我想要搜索[0] =>之间的那些product_id 31337和[1] => 31366同样到陆地我想找到Between [0] =>之间的土地12和[1] => 23

现在说我有一个变量$filters,其中包含上面的数组,我将它像这样传递给下面的查询。

public function scopeDynamicInBetweenFilter($query, $filters)
    {
        if(!empty($filters)){
            return $query->whereBetween($filters);
        }
        return $query;
    }

它给了我一个错误

  

类型错误:函数Illuminate \ Database \ Query \ Builder :: whereBetween(),1通过且至少2个预期的参数太少

中确实如此
Builder->whereBetween('product_id' => array('31337', '31366'))->whereBetween('lands' => array('12', '23'))

可以做些什么来实现这一目标。

2 个答案:

答案 0 :(得分:0)

试试这个:

if(!empty($filters)){
    return $query->whereBetween('product_id', $filters['product_id'])->whereBetween('lands', $filters['lands']);
}

答案 1 :(得分:0)

您可以尝试循环过滤器并将其应用于查询

{{1}}
相关问题