@@ 98-111 (lines=14) @@ | ||
95 | /** |
|
96 | * @return array |
|
97 | */ |
|
98 | public static function getBest() |
|
99 | { |
|
100 | $result = MatchPlayer::selectRaw( |
|
101 | 'player_id, COUNT(*) as appearances ,AVG(vote) avg, SUM(goals) goals' |
|
102 | )->where('goals', '>', 0) |
|
103 | ->orderByRaw('SUM(goals) DESC,COUNT(*) DESC') |
|
104 | ->groupBy('player_id')->take(20)->get()->keyBy('player_id')->toArray(); |
|
105 | $players = Player::whereIn('id', array_keys($result))->get()->toArray(); |
|
106 | $result = array_map(function ($player) use ($result) { |
|
107 | $player['stats'] = $result[$player['id']]; |
|
108 | return $player; |
|
109 | }, $players); |
|
110 | return $result; |
|
111 | } |
|
112 | } |
@@ 124-137 (lines=14) @@ | ||
121 | /** |
|
122 | * @return array |
|
123 | */ |
|
124 | public static function getBest() |
|
125 | { |
|
126 | $result = Match::selectRaw('winner_id as id, COUNT(*) as won') |
|
127 | ->whereNotNull('winner_id')->where('winner_id', '!=', 0) |
|
128 | ->orderByRaw('COUNT(*) DESC')->groupBy('winner_id') |
|
129 | ->take(20)->get()->keyBy('id')->toArray(); |
|
130 | $teams = Team::whereIn('id', array_keys($result))->get()->toArray(); |
|
131 | $result = array_map(function ($team) use ($result) { |
|
132 | $team['stats'] = $result[$team['id']]; |
|
133 | return $team; |
|
134 | }, $teams); |
|
135 | ||
136 | return $result; |
|
137 | } |
|
138 | ||
139 | } |