Laravel whereIn OR whereIn

前端 未结 5 1600
盖世英雄少女心
盖世英雄少女心 2020-12-29 21:43

I\'m making a products search by filters:

My code:

->where(function($query) use($filter)
{
  if(!empty($filter)){
    foreach ($filter as $key =&g         


        
5条回答
  •  情话喂你
    2020-12-29 22:11

    Yes, orWhereIn is a method that you can use.

    I'm fairly sure it should give you the result you're looking for, however, if it doesn't you could simply use implode to create a string and then explode it (this is a guess at your array structure):

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

提交回复
热议问题