validate([ 'q' => 'required|string|min:2', 'category_id' => 'nullable|exists:categories,id', 'author_id' => 'nullable|exists:users,id', 'per_page' => 'nullable|integer|min:1|max:100', ]); $perPage = $request->input('per_page', 10); $results = $this->searchService->searchPosts( $request->input('q'), $request->only(['category_id', 'author_id']), $perPage ); return response()->json([ 'data' => PostResource::collection($results), 'pagination' => [ 'total' => $results->total(), 'per_page' => $results->perPage(), 'current_page' => $results->currentPage(), 'last_page' => $results->lastPage(), ], ]); } public function relatedPosts(Request $request, int $postId): JsonResponse { $post = Post::findOrFail($postId); $relatedPosts = $this->searchService->getRelatedPosts($post); return response()->json([ 'data' => PostResource::collection($relatedPosts), ]); } }