App\Http\Controllers\MatchesController::history PHP Method

history() public method

public history ( $match_id )
    public function history($match_id)
    {
        $since = Request::input('since', 0);
        $full = Request::input('full', false) === 'true';
        $match = Match::findOrFail($match_id);
        $events = $match->events()->with(['game.beatmap.beatmapset', 'game.scores' => function ($query) {
            $query->with('game')->default();
        }])->where('event_id', '>', $since);
        if ($full) {
            $events->default();
        } else {
            $events->orderBy('event_id', 'desc')->take(config('osu.mp-history.event-count'));
        }
        $events = $events->get();
        if (!$full) {
            $events = $events->reverse();
        }
        $userIds = [];
        foreach ($events as $event) {
            if ($event->user_id) {
                $userIds[] = $event->user_id;
            }
            if ($event->game) {
                foreach ($event->game->scores as $score) {
                    $userIds[] = $score->user_id;
                }
            }
        }
        $users = User::with('country')->whereIn('user_id', array_unique($userIds))->get();
        $users = json_collection($users, new UserCompactTransformer(), 'country');
        $events = json_collection($events, new EventTransformer(), ['game.beatmap.beatmapset', 'game.scores']);
        return ['events' => $events, 'users' => $users, 'all_events_count' => $match->events()->count()];
    }
MatchesController