Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use whereIn to check multiple columns?

I have this query:

$query->whereHas($key,function($q) use($option){
            $q->whereIn('district', $option);
            $q->whereIn('region', $option);
          });

But its not working. I want to check district and region and i get an array from $option

like image 751
None Avatar asked Sep 20 '25 13:09

None


1 Answers

For AND use:

$query->whereHas($key,function($q) use($option){
        $q->whereIn('district', $option)
          ->whereIn('region', $option);
    });

For OR:

$query->whereHas($key,function($q) use($option){
        $q->whereIn('district', $option)
          ->orWhereIn('region', $option);
    });
like image 108
Alexey Mezenin Avatar answered Sep 23 '25 04:09

Alexey Mezenin