feat: add group media and music
This commit is contained in:
@@ -89,6 +89,40 @@ public function show($id)
|
||||
return response()->json($category);
|
||||
}
|
||||
|
||||
// Category with each of its sub-categories and that sub-category's playlists.
|
||||
public function grouped($id)
|
||||
{
|
||||
$category = MusicCategory::with([
|
||||
'image',
|
||||
'subcategories' => function ($q) {
|
||||
$q->orderBy('order')->with([
|
||||
'image',
|
||||
'playlists' => function ($p) {
|
||||
$p->where('is_active', true)->with('image')->orderBy('order');
|
||||
},
|
||||
]);
|
||||
},
|
||||
])->findOrFail($id);
|
||||
|
||||
return response()->json([
|
||||
'category' => [
|
||||
'id' => $category->id,
|
||||
'title' => $category->name,
|
||||
'description' => $category->description,
|
||||
'image_url' => $category->image?->url,
|
||||
],
|
||||
'sub_categories' => $category->subcategories->map(fn ($sub) => [
|
||||
'sub_category' => [
|
||||
'id' => $sub->id,
|
||||
'title' => $sub->name,
|
||||
'description' => $sub->description,
|
||||
'image_url' => $sub->image?->url,
|
||||
],
|
||||
'playlists' => $sub->playlists,
|
||||
])->values(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$category = MusicCategory::findOrFail($id);
|
||||
|
||||
Reference in New Issue
Block a user