fix
This commit is contained in:
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user