Created statistics personal and general
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user