I dont know how to describe this problem. Lets say i have this table in my database:
Код: Выделить всё
| Team | Zone |
| ---- | ---- |
| Alfa | A |
| Alfa | BB |
| Alfa | CCC |
| Beta | A |
| Beta | CCC |
| Beta | DDDD |
| Crit | BB |
| Crit | CCC |

What i wanted are:
- If i enter 'A' and 'CCC' in the said form, it will show team Alfa and Beta
- If i enter 'BB' and 'CCC' in the said form, it will show team Alfa and Crit
- If i enter only 'BB' in the said form, it will show team Alfa and Crit
Код: Выделить всё
$find = DB::table('team_zone_area')->select(
'team'
);
if(isset($req->search_zones)){
$find = $find->where('zone', $req->search_zones[0]);
if(count($req->search_zones) > 1){
for($j = 1; $j < count($req->search_zones); $j++){
$find = $find->where('zone', $req->search_zones[$j]);
}
}
}
$find = $find->whereNull('deleted_at')
->groupBy('team')
->get();
Then i tried to tweak the code
Код: Выделить всё
if(count($req->search_zones) > 1)Код: Выделить всё
if(count($req->search_zones) > 1){
for($j = 1; $j < count($req->search_zones); $j++){
$find = $find->orWhere('zone', $req->search_zones[$j]);
}
}
Anyone have idea what the query supposed to be?
Источник: https://stackoverflow.com/questions/781 ... e-variable
Мобильная версия