From 860dbfb54e959eba2abad0c52749783097ebe74c Mon Sep 17 00:00:00 2001 From: gbanyan Date: Sat, 7 Feb 2026 16:36:07 +0800 Subject: [PATCH] Eager-load categories on related articles in API response The related articles query was missing ->with(['categories']), causing the frontend ArticleCard to crash on undefined categories. Co-Authored-By: Claude Opus 4.6 --- app/Http/Controllers/Api/ArticleController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ArticleController.php b/app/Http/Controllers/Api/ArticleController.php index 9c85ac1..eb30485 100644 --- a/app/Http/Controllers/Api/ArticleController.php +++ b/app/Http/Controllers/Api/ArticleController.php @@ -60,7 +60,8 @@ class ArticleController extends Controller $article->incrementViewCount(); // Get related articles (same content_type, excluding current) - $related = Article::active() + $related = Article::with(['categories']) + ->active() ->forAccessLevel() ->where('content_type', $article->content_type) ->where('id', '!=', $article->id)