Ejemplo n.º 1
0
 /**
  * @return array
  */
 public static function getBest()
 {
     $result = MatchPlayer::selectRaw('player_id, COUNT(*) as appearances , AVG(vote) avg, SUM(goals) goals')->where('goals', '>', 0)->orderByRaw('SUM(goals) DESC,COUNT(*) DESC')->groupBy('player_id')->take(self::PLAYER_STATS_LIMIT)->get()->keyBy('player_id')->toArray();
     $players = Player::with('team')->whereIn('id', array_keys($result))->get()->toArray();
     $result = array_map(function ($player) use($result) {
         return array_merge($player, $result[$player['id']]);
     }, $players);
     return $result;
 }