published() ->where('id', $id) ->first(); if (! $artwork) { return response()->json(['error' => 'Not found'], 404); } // Write persistent event log (auth user_id or null for guests). $this->stats->logViewEvent((int) $artwork->id, $request->user()?->id); // Apply the increment immediately so counters stay fresh in Studio. $this->stats->incrementViews((int) $artwork->id, 1, defer: false); $viewerId = $request->user()?->id; if ($artwork->user_id !== null && (int) $artwork->user_id !== (int) ($viewerId ?? 0)) { $this->xp->awardArtworkViewReceived( (int) $artwork->user_id, (int) $artwork->id, $viewerId, (string) $request->ip(), ); } return response()->json(['ok' => true, 'counted' => true]); } }