Created statistics personal and general

This commit is contained in:
Edd
2025-12-31 23:57:54 +00:00
parent 45d8aa0035
commit 16f8d3bdfc
4 changed files with 240 additions and 25 deletions
@@ -29,16 +29,23 @@ class StatisticsController extends Controller
{
$type = $request->query('type');
$query = User::where('type', 'P')
$leaderboard = User::where('type', 'P')
->withCount(['wonGames' => function ($query) use ($type) {
if ($type) {
$query->where('type', $type);
}
}])
->orderBy('won_games_count', 'desc')
->take(10);
->paginate(10);
$leaderboard = $query->get(['id', 'nickname', 'photo_avatar_filename']);
$leaderboard->through(function ($user) {
return [
'id' => $user->id,
'nickname' => $user->nickname,
'photo_avatar_filename' => $user->photo_avatar_filename,
'won_games_count' => $user->won_games_count,
];
});
return response()->json($leaderboard);
}