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 <noreply@anthropic.com>
This commit is contained in:
2026-02-07 16:36:07 +08:00
parent dd7077f77b
commit 860dbfb54e

View File

@@ -60,7 +60,8 @@ class ArticleController extends Controller
$article->incrementViewCount(); $article->incrementViewCount();
// Get related articles (same content_type, excluding current) // Get related articles (same content_type, excluding current)
$related = Article::active() $related = Article::with(['categories'])
->active()
->forAccessLevel() ->forAccessLevel()
->where('content_type', $article->content_type) ->where('content_type', $article->content_type)
->where('id', '!=', $article->id) ->where('id', '!=', $article->id)