API响应中的条目是重复的,api应该在游戏中返回更多的用户积分。
评分资源:
public function toArray($request)
{
$highestScores = Score::where('user_id', $this->user->id)
->select('game_id', 'version_id', DB::raw('MAX(score) as max_score'))
->groupBy('game_id', 'version_id', 'user_id')
->get();
$gameIds = $highestScores->pluck('game_id');
$games = Game::whereIn('id', $gameIds)->get();
return $highestScores->map(function ($score) use ($games) {
$game = $games->firstWhere('id', $score->game_id);
return [
'game' => new UserGamesResource($game),
'score' => $score->max_score,
'timestamp' => Carbon::parse($score->created_at)->toIso8601String(),
];
})->toArray();
}
回复:
DB:
我尝试了很多事情,但我对一切都感到困惑。请帮帮我
1条答案
按热度按时间zvms9eto1#
试试这个: