Php 拉维

Php 拉维,php,mysql,laravel,laravel-4,query-builder,Php,Mysql,Laravel,Laravel 4,Query Builder,我正在通过过滤器进行产品搜索: 我的代码: ->where(function($query) use($filter) { if(!empty($filter)){ foreach ($filter as $key => $value) { $f = explode(",", $value); $query-> whereIn('products.value', $f); }

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

我的代码:

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

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

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

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

你在Laravel中有一个
函数。它采用与
相同的参数,其中
函数

它不在文档中,但您可以在LaravelAPI中找到它。

这应该给你这个:

$query-> orWhereIn('products.value', $f);

是,
或其中
是您可以使用的方法

我很确定它会给出您想要的结果,但是,如果没有,您可以简单地使用
内爆
创建一个字符串,然后将其分解(这是对数组结构的猜测):

//输出@input$stakeholderId=1


//选择group_concat(dms_涉众_permissions.fid)作为fid,
dms_涉众_permissions
权限
来自
dms_涉众_permissions
其中
dms_涉众_permissions
涉众id
=4或(
dms\u涉众权限
涉众id
=1和
dms\u涉众权限
在(1,2,3)中的权限

例如,如果您有多个where或where条件,并且希望放在括号中,请执行以下操作:

$getrecord = DiamondMaster::where('is_delete','0')->where('user_id',Auth::user()->id);
if(!empty($request->stone_id))
{
    $postdata = $request->stone_id;
    $certi_id =trim($postdata,",");
    $getrecord = $getrecord->whereIn('id',explode(",", $certi_id))
                           ->orWhereIn('Certi_NO',explode(",", $certi_id));     
}
$getrecord = $getrecord->get();

是,
orwhere
where子句方法存在于Laravel中。有关详细信息,请参阅官方Laravel查询生成器文档的以下链接

文档链接:

有两种方法可以获得以下输出

and (products.value in (Bomann, PHILIPS) OR products.value in (red,white))
  • 使用
    或其中
  • 输出:

    select * from `products` where `color` = 'blue' and `value` in (Bomann, PHILIPS) OR `value` in (red,white)) 
    
    select * from `products` where `color` = 'blue' and `value` in (Bomann, PHILIPS) OR (`value` in (red,white)) 
    
    
  • 使用
    或where
    其中
  • 输出:

    select * from `products` where `color` = 'blue' and `value` in (Bomann, PHILIPS) OR `value` in (red,white)) 
    
    select * from `products` where `color` = 'blue' and `value` in (Bomann, PHILIPS) OR (`value` in (red,white)) 
    
    

    是的,它的确切名称是
    或其中的
    。伙计,你应该先试试。@HassanAzimi你的评论是错误和误导的。[链接]()
    
    $query2 = Product::where('color', 'blue')
        ->whereIn('value', ['Bomann', 'PHILIPS'])
        ->orWhere(function ($query) {
            $query->whereIn('value', ['Bomann', 'PHILIPS']);
        })
        ->get();
    
    select * from `products` where `color` = 'blue' and `value` in (Bomann, PHILIPS) OR (`value` in (red,white))