/** * @return Builder */ public function guardians(Season $season) { $group = $this; return User::whereHas('players', function (Builder $q) use($season, $group) { $q->join('player_season', 'player_season.player_id', '=', 'players.id')->active($season)->whereHas('groups', function (Builder $q) use($season, $group) { $q->where('group_id', $group->id); $q->where('season_id', $season->id); }); }); }