*/ private const RESOURCES = [ 'posts' => Post::class, 'categories' => Category::class, 'tags' => Tag::class, 'projects' => Project::class, 'project-categories' => ProjectCategory::class, 'about-me' => AboutMe::class, ]; /** * Raw rows for content management. * * The public API intentionally returns display-oriented payloads: single * translated values, reshaped image arrays, no internal ids for some * fields. An editing form needs the stored row instead, including both * locales, so this endpoint serialises the model as-is. */ public function index(Request $request, string $resource): JsonResponse { $model = self::RESOURCES[$resource] ?? null; if ($model === null) { return response()->json(['message' => 'Unknown admin resource.'], 404); } $rows = $model::query()->orderByDesc('id')->get(); return response()->json(['data' => $rows]); } /** * Field names accepted per resource, so the admin panel and the write * endpoints cannot drift apart silently. */ public static function writableFields(string $resource): array { return match ($resource) { 'posts' => ['title', 'body', 'excerpt', 'slug', 'author_id', 'category_id', 'featured_image', 'views', 'likes', 'published_at', 'tags'], 'categories' => ['name', 'slug', 'description', 'short_description', 'image'], 'tags' => ['name', 'slug'], 'projects' => ['category_id', 'image1', 'image2', 'title_fa', 'title_en', 'description_fa', 'description_en'], 'about-me' => ['image', 'title_fa', 'title_en', 'description_fa', 'description_en'], default => [], }; } }