orderBy('display_order')->get(['id', 'name', 'articles_count', 'display_order']); return response()->json([ 'data' => $categories, ]); } public function articles(Request $request, int $id, BlogSettings $blog): JsonResponse { Category::query()->findOrFail($id); $perPage = max(1, min(50, $request->integer('per_page') ?: $blog->posts_per_page)); $articles = Article::query() ->with(['category:id,name', 'tags:id,name']) ->visible() ->published() ->where('category_id', $id) ->orderByDesc('published_at') ->paginate($perPage); return response()->json([ 'data' => $articles->items(), 'meta' => [ 'current_page' => $articles->currentPage(), 'last_page' => $articles->lastPage(), 'per_page' => $articles->perPage(), 'total' => $articles->total(), ], ]); } }