This commit is contained in:
2026-06-13 18:51:45 +03:30
parent ab10f03afe
commit f097a1e50c
+18 -7
View File
@@ -15,25 +15,36 @@ class CategoryController extends Controller
public function index(Request $request) public function index(Request $request)
{ {
$type = $request->input('type');
// Playlist categories live in their own table (music_categories); serve // Playlist categories live in their own table (music_categories); serve
// them here too so the front has one /categories?type=... entry point. // them here too so the front has one /categories entry point.
if ($request->input('type') === Category::TYPE_PLAYLIST) { if ($type === Category::TYPE_PLAYLIST) {
return response()->json($this->playlistCategories($request)); return response()->json($this->playlistCategories($request)->values());
} }
$query = Category::query()->withCount('subcategories'); $query = Category::query()->withCount('subcategories');
if ($request->filled('type')) { if ($request->filled('type')) {
$query->where('type', $request->input('type')); $query->where('type', $type);
} }
if ($request->boolean('with_subcategories')) { if ($request->boolean('with_subcategories')) {
$query->with('subcategories'); $query->with('subcategories');
} }
return response()->json( $categories = $query->orderBy('name')->get();
$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. // Music categories normalized to the generic category shape.