orderByDesc('satoshis') ->orderBy('achieved_at') ->get() ->map(fn (Highscore $highscore) => [ 'npub' => $highscore->npub, 'name' => $highscore->name, 'satoshis' => $highscore->satoshis, 'blocks' => $highscore->blocks, 'datetime' => $highscore->achieved_at->toIso8601String(), ]); return response()->json([ 'data' => $highscores, ]); } public function store(StoreHighscoreRequest $request): JsonResponse { $validated = $request->validated(); $achievedAt = CarbonImmutable::parse($validated['datetime']); $highscore = Highscore::query()->firstOrNew([ 'npub' => $validated['npub'], 'achieved_at' => $achievedAt, ]); $highscore->satoshis = (int) $validated['satoshis']; $highscore->blocks = (int) $validated['blocks']; if (array_key_exists('name', $validated)) { $highscore->name = $validated['name']; } $highscore->save(); Log::info('Highscore submission received', [ 'npub' => $highscore->npub, 'name' => $highscore->name, 'satoshis' => $highscore->satoshis, 'blocks' => $highscore->blocks, 'datetime' => $highscore->achieved_at->toIso8601String(), ]); return response()->json([ 'message' => 'Highscore received', 'data' => [ 'npub' => $highscore->npub, 'name' => $highscore->name, 'satoshis' => $highscore->satoshis, 'blocks' => $highscore->blocks, 'datetime' => $highscore->achieved_at->toIso8601String(), ], ], 202); } }