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