Hey!
If I got it right you want all locations that have the all the games from the array you are passing in as parameter of the scope (when games can't coexist).
If that is the case:
public function scopeWithGames($query, $games, $gamesCoexist)
{
if(! count($games)) {
return $query;
}
if($gamesCoexist) {
return $query->whereHas('machines', function($machines) use($games) {
foreach($games as $game) {
$machines->where('game_id', $game);
}
});
}
return $query->whereHas('machines', function($machines) use($games) {
$machines->whereIn('game_id', $games);
});
}
Hope this helps