diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 1cc0769..14eefeb 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -15,25 +15,36 @@ class CategoryController extends Controller public function index(Request $request) { + $type = $request->input('type'); + // Playlist categories live in their own table (music_categories); serve - // them here too so the front has one /categories?type=... entry point. - if ($request->input('type') === Category::TYPE_PLAYLIST) { - return response()->json($this->playlistCategories($request)); + // them here too so the front has one /categories entry point. + if ($type === Category::TYPE_PLAYLIST) { + return response()->json($this->playlistCategories($request)->values()); } $query = Category::query()->withCount('subcategories'); if ($request->filled('type')) { - $query->where('type', $request->input('type')); + $query->where('type', $type); } if ($request->boolean('with_subcategories')) { $query->with('subcategories'); } - return response()->json( - $query->orderBy('name')->get() - ); + $categories = $query->orderBy('name')->get(); + + // No type filter → also fold in the playlist (music) categories so the + // response contains every category across both tables. + if (!$request->filled('type')) { + $categories = $categories + ->concat($this->playlistCategories($request)) + ->sortBy('name') + ->values(); + } + + return response()->json($categories); } // Music categories normalized to the generic category shape.