public function getTournamentSeasonStatisticPlayerBombardiers($tournamentSeason)
{
return Player::whereHas('positionFirstMatchLogs', function ($query) use ($tournamentSeason) {
$query->whereHas('match', function ($query) use ($tournamentSeason) {
$query->ofTournamentSeason($tournamentSeason->id);
})->goalAmount();
})
//->select('players.name','players.slug', 'players.big_image', 'players.small_image', 'players.position')
->with('currentTeam')
// ->with([
// 'playerTeams' => function ($query) use ($tournamentSeason) {
// $query->with(array('team' => function ($team) {
// $team->select('id', 'name', 'logotip', 'slug');
// }))
// ->season($tournamentSeason->start_date, $tournamentSeason->finish_date);
// }
// ])
->withCount([
'positionFirstMatchLogs as goals_count' => function ($query) use ($tournamentSeason) {
$query->whereHas('match', function ($query) use ($tournamentSeason) {
$query->ofTournamentSeason($tournamentSeason->id);
})->goalAmount();
},
'positionFirstMatchLogs as penalty_goals_count' => function ($query) use ($tournamentSeason) {
$query->whereHas('match', function ($query) use ($tournamentSeason) {
$query->ofTournamentSeason($tournamentSeason->id);
})->penalty();
},
'positionFirstMatchLogs as matches_count' => function ($query) use ($tournamentSeason) {
$query->whereHas('match', function ($query) use ($tournamentSeason) {
$query->ofTournamentSeason($tournamentSeason->id)->playedMatch();
});
},
])
->orderBy('goals_count', 'DESC')
->orderBy('matches_count', 'ASC')
->paginate(10);
}