Cba季后赛门票在哪里买:Laravel在哪里或在哪里

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

我的代码:

->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
51

You could have searched just forwhereInfunction in the core to see that.Here you are.This must answer all your questions

/**
 * 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 ume 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;
}

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

38

您在 Laravel 中有一个orWhereIn函数,它采用与whereIn函数相同的参数。

它不在文档中,但您可以在 laravel API 中找到它。http://laravel.com/api/4.1/

这应该给你这个:

$query-> orWhereIn('products.value', $f);
8
$query = DB::table('dms_stakeholder_permissions');
$query->select(DB::raw('group_concat(dms_stakeholder_permissions.fid) as fid'),'dms_stakeholder_permissions.rights');
$query->where('dms_stakeholder_permissions.stakeholder_id','4');
$query->orWhere(function($subquery)  use ($stakeholderId){
            $subquery->where('dms_stakeholder_permissions.stakeholder_id',$stakeholderId);
            $subquery->whereIn('dms_stakeholder_permissions.rights',array('1','2','3'));
    });
 $result = $query->get();
return $result;

/ / OUTPUT @ input $stakeholderId =1

/ / 从dms_stakeholder_permissions中选择 group_concat (dms_stakeholder_permissions.fid) 作为 fid,dms_stakeholder_permissionss.rights,其中dms_stakeholder_permissions.stakeholder_id= 4 或 (dms_stakeholder_permissions= 1)。

7

是的,orWhereIn是可以使用的方法。

我相当肯定它应该给你你正在寻找的结果,但是,如果它不,你可以简单地使用implode创建一个字符串,然后爆炸(这是你的数组结构的猜测):

$values = implode(',', array_map(function($value)
{
    return trim($value, ',');
}, $filters));
$query->whereIn('products.value', explode(',' $values));

本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处

(863)
Cba总决赛在哪看:JavaFX构建与阴影 位置是必需的 它在哪里看
上一篇
海关编码查询系统:Chrome海关标签
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(81条)