From 5ae1d1a6325392a04d2d5c61afb52f39b997982c Mon Sep 17 00:00:00 2001 From: Parsa Aghayi Date: Thu, 1 Oct 2026 16:00:06 -0400 Subject: [PATCH] Eager-load relations the admin read API returns Edit forms are populated from a single request, so posts need their tags and projects their category attached; otherwise the tag multi-select and category picker come back empty. --- .../Api/Admin/AdminResourceController.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/Admin/AdminResourceController.php b/app/Http/Controllers/Api/Admin/AdminResourceController.php index 1b19599..eb7cbf1 100644 --- a/app/Http/Controllers/Api/Admin/AdminResourceController.php +++ b/app/Http/Controllers/Api/Admin/AdminResourceController.php @@ -28,6 +28,17 @@ class AdminResourceController extends Controller 'about-me' => AboutMe::class, ]; + /** + * Relations eager loaded per resource, so an editing form is populated + * from a single request instead of a fan-out of lookups. + * + * @var array> + */ + private const RELATIONS = [ + 'posts' => ['tags'], + 'projects' => ['category'], + ]; + /** * Raw rows for content management. * @@ -44,7 +55,7 @@ class AdminResourceController extends Controller return response()->json(['message' => 'Unknown admin resource.'], 404); } - $rows = $model::query()->orderByDesc('id')->get(); + $rows = $model::query()->with(self::RELATIONS[$resource] ?? [])->orderByDesc('id')->get(); return response()->json(['data' => $rows]); }