gpt4 book ai didi

php - Laravel whereIn 或 whereIn

转载 作者:IT老高 更新时间:2023-10-28 23:50:09 29 4
gpt4 key购买 nike

我正在通过过滤器搜索产品:

我的代码:

->where(function($query) use($filter)
{
if(!empty($filter)){
foreach ($filter as $key => $value) {
$f = explode(",", $value);
$query-> whereIn('products.value', $f);
}
}
})

查询:

and (products.value in (Bomann, PHILIPS) and products.value in (red,white)) 

但我需要:

and (products.value in (Bomann, PHILIPS) OR products.value in (red,white)) 

Laravel 中有没有类似的东西:

orWhereIn

最佳答案

您可以只搜索核心中的 whereIn 函数来查看。给你。这必须回答你所有的问题

/**
* Add a "where in" clause to the query.
*
* @param string $column
* @param mixed $values
* @param string $boolean
* @param bool $not
* @return \Illuminate\Database\Query\Builder|static
*/
public function whereIn($column, $values, $boolean = 'and', $not = false)
{
$type = $not ? 'NotIn' : 'In';

// If the value of the where in clause is actually a Closure, we will assume that
// the developer is using a full sub-select for this "in" statement, and will
// execute those Closures, then we can re-construct the entire sub-selects.
if ($values instanceof Closure)
{
return $this->whereInSub($column, $values, $boolean, $not);
}

$this->wheres[] = compact('type', 'column', 'values', 'boolean');

$this->bindings = array_merge($this->bindings, $values);

return $this;
}

看看它有第三个 bool 参数。祝你好运。

关于php - Laravel whereIn 或 whereIn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22758819/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com