select(['id', 'user_id', 'title', 'slug']) ->find($id); if (! $artwork) { return response()->json([ 'prev_id' => null, 'next_id' => null, 'prev_url' => null, 'next_url' => null, 'prev_slug' => null, 'next_slug' => null, 'prev_preview' => null, 'next_preview' => null, ]); } return response()->json($this->navigation->navigationFor($artwork)); } /** * GET /api/artworks/{id}/page * * Returns full artwork resource by numeric ID for client-side (no-reload) navigation. */ public function pageData(Request $request, int $id): JsonResponse { if ($request->boolean('prefetch')) { return $this->prefetchData($id); } $artwork = Artwork::with(['user.profile', 'categories.contentType', 'categories.parent.contentType', 'tags', 'stats']) ->published() ->find($id); if (! $artwork) { return response()->json(['error' => 'Not found'], 404); } $resource = (new ArtworkResource($artwork))->toArray(request()); $resource['navigation'] = $this->navigation->navigationFor($artwork); return response()->json($resource); } private function prefetchData(int $id): JsonResponse { $artwork = Artwork::query() ->published() ->select(['id', 'title', 'slug', 'hash', 'file_path', 'file_name']) ->find($id); if (! $artwork) { return response()->json(['error' => 'Not found'], 404); } return response()->json([ 'id' => (int) $artwork->id, 'title' => (string) $artwork->title, 'slug' => (string) $artwork->slug, 'thumbs' => [ 'md' => ThumbnailPresenter::present($artwork, 'md'), 'lg' => ThumbnailPresenter::present($artwork, 'lg'), ], ]); } }