Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56f0e8dbe2 | ||
|
|
230bfc2ad8 | ||
|
|
8923810df3 | ||
|
|
bac1e46848 | ||
|
|
2352c34062 | ||
|
|
74e42d5fb4 | ||
|
|
5800f64f88 | ||
|
|
d8f769e738 |
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Category;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class CategoryController extends Controller
|
||||||
|
{
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
$query = Category::query()->withCount('subcategories');
|
||||||
|
|
||||||
|
if ($request->boolean('with_subcategories')) {
|
||||||
|
$query->with('subcategories');
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(
|
||||||
|
$query->orderBy('name')->get()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$data = $request->validate([
|
||||||
|
'name' => 'required|string|max:255|unique:categories,name',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$category = Category::create($data);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Category created successfully',
|
||||||
|
'category' => $category,
|
||||||
|
], 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id)
|
||||||
|
{
|
||||||
|
$category = Category::with('subcategories')->withCount('subcategories')->findOrFail($id);
|
||||||
|
|
||||||
|
return response()->json($category);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request, $id)
|
||||||
|
{
|
||||||
|
$category = Category::findOrFail($id);
|
||||||
|
|
||||||
|
$data = $request->validate([
|
||||||
|
'name' => 'required|string|max:255|unique:categories,name,' . $category->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$category->update($data);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Category updated successfully',
|
||||||
|
'category' => $category,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
$category = Category::findOrFail($id);
|
||||||
|
$category->delete();
|
||||||
|
|
||||||
|
return response()->json(['message' => 'Category deleted successfully']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -127,10 +127,11 @@ private function getModelClass($type)
|
|||||||
$models = [
|
$models = [
|
||||||
'music' => \App\Models\Music::class,
|
'music' => \App\Models\Music::class,
|
||||||
'media' => \App\Models\Media::class,
|
'media' => \App\Models\Media::class,
|
||||||
|
'playlist' => \App\Models\MusicPlaylist::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!isset($models[$type])) {
|
if (!isset($models[$type])) {
|
||||||
abort(404, 'Invalid model type');
|
abort(404, 'Invalid model type. Supported types: music, media, playlist');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $models[$type];
|
return $models[$type];
|
||||||
|
|||||||
@@ -0,0 +1,236 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
use App\Models\Like;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class LikeController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Like an item (music or media)
|
||||||
|
*/
|
||||||
|
public function like(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'type' => 'required|string|in:music,media,playlist',
|
||||||
|
'id' => 'required|integer',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$model = $this->getModel($request->type, $request->id);
|
||||||
|
|
||||||
|
if (!$model) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Item not found'
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $model->addLike();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Item liked successfully',
|
||||||
|
'is_liked' => true,
|
||||||
|
'likes_count' => $model->likes_count
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlike an item
|
||||||
|
*/
|
||||||
|
public function unlike(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'type' => 'required|string|in:music,media,playlist',
|
||||||
|
'id' => 'required|integer',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$model = $this->getModel($request->type, $request->id);
|
||||||
|
|
||||||
|
if (!$model) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Item not found'
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $model->removeLike();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Item unliked successfully',
|
||||||
|
'is_liked' => false,
|
||||||
|
'likes_count' => $model->likes_count
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle like status
|
||||||
|
*/
|
||||||
|
public function toggleLike(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'type' => 'required|string|in:music,media,playlist',
|
||||||
|
'id' => 'required|integer',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$model = $this->getModel($request->type, $request->id);
|
||||||
|
|
||||||
|
if (!$model) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Item not found'
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $model->toggleLike();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => $result ? 'Item liked successfully' : 'Item unliked successfully',
|
||||||
|
'is_liked' => $model->is_liked,
|
||||||
|
'likes_count' => $model->likes_count
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all liked items for the authenticated user
|
||||||
|
*/
|
||||||
|
public function myLikedItems(Request $request)
|
||||||
|
{
|
||||||
|
$type = $request->get('type'); // Optional filter by type (music or media)
|
||||||
|
|
||||||
|
$query = Like::with('likeable')
|
||||||
|
->where('user_id', auth()->id());
|
||||||
|
|
||||||
|
if ($type) {
|
||||||
|
$modelClass = $this->getModelClass($type);
|
||||||
|
$query->where('likeable_type', $modelClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
$likedItems = $query->latest()->paginate(20);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'data' => $likedItems,
|
||||||
|
'total' => $likedItems->total(),
|
||||||
|
'types' => [
|
||||||
|
'music' => 'App\\Models\\Music',
|
||||||
|
'media' => 'App\\Models\\Media',
|
||||||
|
'playlist' => 'App\\Models\\MusicPlaylist',
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
// Transform the response
|
||||||
|
// $transformedItems = $likedItems->map(function ($likeItem) {
|
||||||
|
// $item = $likeItem->likeable;
|
||||||
|
|
||||||
|
// if (!$item) return null;
|
||||||
|
|
||||||
|
// $baseData = [
|
||||||
|
// 'like_id' => $likeItem->id,
|
||||||
|
// 'liked_at' => $likeItem->created_at,
|
||||||
|
// 'type' => class_basename($likeItem->likeable_type),
|
||||||
|
// 'is_liked' => true,
|
||||||
|
// ];
|
||||||
|
|
||||||
|
// // Add type-specific data
|
||||||
|
// if ($item instanceof \App\Models\Music) {
|
||||||
|
// return array_merge($baseData, [
|
||||||
|
// 'id' => $item->id,
|
||||||
|
// 'title' => $item->title,
|
||||||
|
// 'artist' => $item->artist,
|
||||||
|
// 'duration' => $item->duration_formatted ?? $item->duration,
|
||||||
|
// 'image_url' => $item->image_url,
|
||||||
|
// 'likes_count' => $item->likes_count,
|
||||||
|
// 'type_display' => 'music'
|
||||||
|
// ]);
|
||||||
|
// } elseif ($item instanceof \App\Models\Media) {
|
||||||
|
// return array_merge($baseData, [
|
||||||
|
// 'id' => $item->id,
|
||||||
|
// 'title' => $item->title,
|
||||||
|
// 'caption' => $item->caption,
|
||||||
|
// 'media_type' => $item->type,
|
||||||
|
// 'duration' => $item->duration,
|
||||||
|
// 'image_url' => $item->image->url ?? null,
|
||||||
|
// 'likes_count' => $item->likes_count,
|
||||||
|
// 'type_display' => 'media'
|
||||||
|
// ]);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return $baseData;
|
||||||
|
// })->filter();
|
||||||
|
|
||||||
|
// return response()->json([
|
||||||
|
// 'data' => $transformedItems,
|
||||||
|
// 'total' => $likedItems->total(),
|
||||||
|
// 'current_page' => $likedItems->currentPage(),
|
||||||
|
// 'last_page' => $likedItems->lastPage(),
|
||||||
|
// 'per_page' => $likedItems->perPage(),
|
||||||
|
// ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if specific item is liked by user
|
||||||
|
*/
|
||||||
|
public function checkLiked(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'type' => 'required|string|in:music,media,playlist',
|
||||||
|
'id' => 'required|integer',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$model = $this->getModel($request->type, $request->id);
|
||||||
|
|
||||||
|
if (!$model) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Item not found'
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'is_liked' => $model->is_liked,
|
||||||
|
'likes_count' => $model->likes_count
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get top liked items
|
||||||
|
*/
|
||||||
|
public function topLiked(Request $request)
|
||||||
|
{
|
||||||
|
$type = $request->get('type', 'music'); // Default to music
|
||||||
|
$limit = $request->get('limit', 10);
|
||||||
|
|
||||||
|
$modelClass = $this->getModelClass($type);
|
||||||
|
|
||||||
|
$items = $modelClass::with(['image'])
|
||||||
|
->withCount('likes')
|
||||||
|
->where(function($query) use ($modelClass) {
|
||||||
|
if (property_exists($modelClass, 'type')) {
|
||||||
|
$query->where('type', 'public');
|
||||||
|
}
|
||||||
|
if (property_exists($modelClass, 'visibility')) {
|
||||||
|
$query->where('visibility', 'public');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->orderBy('likes_count', 'desc')
|
||||||
|
->limit($limit)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'data' => $items,
|
||||||
|
'type' => $type,
|
||||||
|
'total' => $items->count()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getModel($type, $id)
|
||||||
|
{
|
||||||
|
$modelClass = $this->getModelClass($type);
|
||||||
|
return $modelClass::find($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getModelClass($type)
|
||||||
|
{
|
||||||
|
$models = [
|
||||||
|
'music' => \App\Models\Music::class,
|
||||||
|
'media' => \App\Models\Media::class,
|
||||||
|
'playlist' => \App\Models\MusicPlaylist::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $models[$type] ?? null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ public function store(Request $request)
|
|||||||
'caption' => 'nullable|string',
|
'caption' => 'nullable|string',
|
||||||
'type' => 'required|in:audio,video',
|
'type' => 'required|in:audio,video',
|
||||||
'category_id' => 'nullable|exists:categories,id',
|
'category_id' => 'nullable|exists:categories,id',
|
||||||
'category_name' => 'nullable|string|max:255',
|
'subcategory_id' => 'nullable|exists:sub_categories,id',
|
||||||
'image_id' => 'nullable|exists:images,id',
|
'image_id' => 'nullable|exists:images,id',
|
||||||
'duration' => 'nullable|integer',
|
'duration' => 'nullable|integer',
|
||||||
'is_premium' => 'nullable|boolean',
|
'is_premium' => 'nullable|boolean',
|
||||||
@@ -31,14 +31,8 @@ public function store(Request $request)
|
|||||||
'tags.*' => 'string',
|
'tags.*' => 'string',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$categoryId = $data['category_id'] ?? null;
|
$categoryId = $data['category_id'] ?? null;
|
||||||
|
|
||||||
if (!$categoryId && isset($data['category_name'])) {
|
|
||||||
$category = Category::firstOrCreate([
|
|
||||||
'name' => $data['category_name']
|
|
||||||
]);
|
|
||||||
$categoryId = $category->id;
|
|
||||||
}
|
|
||||||
$path = null;
|
$path = null;
|
||||||
if ($request->hasFile('file')) {
|
if ($request->hasFile('file')) {
|
||||||
$path = $request->file('file')->store('media', 'public');
|
$path = $request->file('file')->store('media', 'public');
|
||||||
@@ -53,6 +47,7 @@ public function store(Request $request)
|
|||||||
'external_url' => $data['external_url'] ?? null,
|
'external_url' => $data['external_url'] ?? null,
|
||||||
'image_id' => $data['image_id'] ?? null,
|
'image_id' => $data['image_id'] ?? null,
|
||||||
'category_id' => $categoryId,
|
'category_id' => $categoryId,
|
||||||
|
'subcategory_id' => $data['subcategory_id'] ?? null,
|
||||||
'duration' => $data['duration'] ?? null,
|
'duration' => $data['duration'] ?? null,
|
||||||
'visibility' => $data['visibility'] ?? 'public',
|
'visibility' => $data['visibility'] ?? 'public',
|
||||||
'is_premium'=> $data['is_premium'] ?? false
|
'is_premium'=> $data['is_premium'] ?? false
|
||||||
@@ -69,12 +64,12 @@ public function store(Request $request)
|
|||||||
}
|
}
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'Media created successfully',
|
'message' => 'Media created successfully',
|
||||||
'media' => $media->load(['image', 'category' , 'tags']),
|
'media' => $media->load(['image', 'category', 'subCategory', 'tags']),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$query = Media::with(['image', 'category', 'myNote', 'tags','comments'])
|
$query = Media::with(['image', 'category', 'subCategory', 'myNote', 'tags','comments'])
|
||||||
->where(function ($q) {
|
->where(function ($q) {
|
||||||
$q->where('visibility', 'public')
|
$q->where('visibility', 'public')
|
||||||
->orWhere('user_id', auth()->id());
|
->orWhere('user_id', auth()->id());
|
||||||
@@ -91,6 +86,11 @@ public function index(Request $request)
|
|||||||
$query->whereIn('category_id', $categories);
|
$query->whereIn('category_id', $categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->filled('subcategories')) {
|
||||||
|
$subcategories = explode(',', $request->subcategories);
|
||||||
|
$query->whereIn('subcategory_id', $subcategories);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| 2️⃣ Multi Duration Ranges
|
| 2️⃣ Multi Duration Ranges
|
||||||
@@ -322,9 +322,10 @@ public function filters(Request $request)
|
|||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$media = Media::with([
|
$media = Media::with([
|
||||||
'image',
|
'image',
|
||||||
'category',
|
'category',
|
||||||
'myNote',
|
'subCategory',
|
||||||
|
'myNote',
|
||||||
'tags',
|
'tags',
|
||||||
'comments' => function($query) {
|
'comments' => function($query) {
|
||||||
$query->with('user')->latest()->limit(10);
|
$query->with('user')->latest()->limit(10);
|
||||||
@@ -361,6 +362,7 @@ public function show($id)
|
|||||||
'is_premium' => $media->is_premium,
|
'is_premium' => $media->is_premium,
|
||||||
'image' => $media->image,
|
'image' => $media->image,
|
||||||
'category' => $media->category,
|
'category' => $media->category,
|
||||||
|
'sub_category' => $media->subCategory,
|
||||||
'tags' => $media->tags,
|
'tags' => $media->tags,
|
||||||
'myNote' => $media->myNote,
|
'myNote' => $media->myNote,
|
||||||
'is_saved' => $media->is_saved,
|
'is_saved' => $media->is_saved,
|
||||||
@@ -442,9 +444,8 @@ public function update(Request $request, $id)
|
|||||||
'caption' => 'nullable|string',
|
'caption' => 'nullable|string',
|
||||||
'type' => 'nullable|in:audio,video',
|
'type' => 'nullable|in:audio,video',
|
||||||
|
|
||||||
// support both: category_id or category_name
|
|
||||||
'category_id' => 'nullable|exists:categories,id',
|
'category_id' => 'nullable|exists:categories,id',
|
||||||
'category_name' => 'nullable|string|max:255',
|
'subcategory_id' => 'nullable|exists:sub_categories,id',
|
||||||
'is_premium' => 'nullable|boolean',
|
'is_premium' => 'nullable|boolean',
|
||||||
'image_id' => 'nullable|exists:images,id',
|
'image_id' => 'nullable|exists:images,id',
|
||||||
'duration' => 'nullable|integer',
|
'duration' => 'nullable|integer',
|
||||||
@@ -455,16 +456,8 @@ public function update(Request $request, $id)
|
|||||||
'tags.*' => 'string',
|
'tags.*' => 'string',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// --- handle auto-create category ---
|
|
||||||
$categoryId = $data['category_id'] ?? $media->category_id;
|
$categoryId = $data['category_id'] ?? $media->category_id;
|
||||||
|
|
||||||
if (isset($data['category_name'])) {
|
|
||||||
$category = Category::firstOrCreate([
|
|
||||||
'name' => $data['category_name']
|
|
||||||
]);
|
|
||||||
$categoryId = $category->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- handle file replace ---
|
// --- handle file replace ---
|
||||||
if ($request->hasFile('file')) {
|
if ($request->hasFile('file')) {
|
||||||
Storage::disk('public')->delete($media->file_path);
|
Storage::disk('public')->delete($media->file_path);
|
||||||
@@ -477,6 +470,7 @@ public function update(Request $request, $id)
|
|||||||
'caption' => $data['caption'] ?? $media->caption,
|
'caption' => $data['caption'] ?? $media->caption,
|
||||||
'type' => $data['type'] ?? $media->type,
|
'type' => $data['type'] ?? $media->type,
|
||||||
'category_id' => $categoryId,
|
'category_id' => $categoryId,
|
||||||
|
'subcategory_id' => array_key_exists('subcategory_id', $data) ? $data['subcategory_id'] : $media->subcategory_id,
|
||||||
'is_premium' => $data['is_premium'] ?? $media->is_premium,
|
'is_premium' => $data['is_premium'] ?? $media->is_premium,
|
||||||
'duration' => $data['duration'] ?? $media->duration,
|
'duration' => $data['duration'] ?? $media->duration,
|
||||||
'external_url' => $data['external_url'] ?? $media->external_url,
|
'external_url' => $data['external_url'] ?? $media->external_url,
|
||||||
@@ -546,7 +540,7 @@ public function toggleSaveMedia($id)
|
|||||||
// GET saved
|
// GET saved
|
||||||
public function saved()
|
public function saved()
|
||||||
{
|
{
|
||||||
return auth()->user()->savedMedia()->with(['image','category' , 'myNote' , 'tags'])->get();
|
return auth()->user()->savedMedia()->with(['image','category', 'subCategory', 'myNote' , 'tags'])->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function storeNote(Request $request, $mediaId)
|
public function storeNote(Request $request, $mediaId)
|
||||||
|
|||||||
@@ -55,19 +55,45 @@ public function store(Request $request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$playlist = MusicPlaylist::with([
|
$playlist = MusicPlaylist::with([
|
||||||
'category',
|
'category',
|
||||||
'image',
|
'subcategory',
|
||||||
'musics' => function($q) {
|
'image',
|
||||||
$q->where('is_active', true)
|
'musics' => function($q) {
|
||||||
->with(['image', 'tags'])
|
$q->where('is_active', true)
|
||||||
->orderBy('order');
|
->with(['image', 'tags'])
|
||||||
}
|
->orderBy('order');
|
||||||
])->findOrFail($id);
|
},
|
||||||
|
'comments' => function($q) { // Add comments relationship
|
||||||
return response()->json($playlist);
|
$q->with('user')->latest()->limit(10);
|
||||||
}
|
}
|
||||||
|
])->findOrFail($id);
|
||||||
|
$userComment = $playlist->userComment();
|
||||||
|
$comments = $playlist->comments()
|
||||||
|
->with('user')
|
||||||
|
->latest()
|
||||||
|
->paginate(15);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'playlist' => $playlist,
|
||||||
|
'statistics' => [
|
||||||
|
'total_musics' => $playlist->musics->count(),
|
||||||
|
'total_duration' => $playlist->total_duration,
|
||||||
|
'total_comments' => $playlist->comments_count,
|
||||||
|
'total_likes' => $playlist->likes_count,
|
||||||
|
'total_saves' => $playlist->saved_count,
|
||||||
|
],
|
||||||
|
'user_interaction' => [
|
||||||
|
'has_commented' => $playlist->has_user_commented,
|
||||||
|
'user_comment' => $playlist->user_comment,
|
||||||
|
'user_comment_id' => $playlist->user_comment_id,
|
||||||
|
'has_liked' => $playlist->is_liked,
|
||||||
|
'has_saved' => $playlist->is_saved,
|
||||||
|
],
|
||||||
|
'comments' => $comments,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function update(Request $request, $id)
|
public function update(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class SaveController extends Controller
|
|||||||
public function save(Request $request)
|
public function save(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'type' => 'required|string|in:music,media,breathing-template',
|
'type' => 'required|string|in:music,media,breathing-template,playlist',
|
||||||
'id' => 'required|integer',
|
'id' => 'required|integer',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ public function save(Request $request)
|
|||||||
public function unsave(Request $request)
|
public function unsave(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'type' => 'required|string|in:music,media,breathing-template',
|
'type' => 'required|string|in:music,media,breathing-template,playlist',
|
||||||
'id' => 'required|integer',
|
'id' => 'required|integer',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ public function unsave(Request $request)
|
|||||||
public function toggleSave(Request $request)
|
public function toggleSave(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'type' => 'required|string|in:music,media,breathing-template',
|
'type' => 'required|string|in:music,media,breathing-template,playlist',
|
||||||
'id' => 'required|integer',
|
'id' => 'required|integer',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -112,6 +112,7 @@ public function mySavedItems(Request $request)
|
|||||||
'music' => 'App\\Models\\Music',
|
'music' => 'App\\Models\\Music',
|
||||||
'media' => 'App\\Models\\Media',
|
'media' => 'App\\Models\\Media',
|
||||||
'breathing-template' => 'App\\Models\\BreathingTemplate',
|
'breathing-template' => 'App\\Models\\BreathingTemplate',
|
||||||
|
'playlist' => 'App\\Models\\MusicPlaylist',
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -121,7 +122,7 @@ public function mySavedItems(Request $request)
|
|||||||
public function checkSaved(Request $request)
|
public function checkSaved(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'type' => 'required|string|in:music,media,breathing-template',
|
'type' => 'required|string|in:music,media,breathing-template,playlist',
|
||||||
'id' => 'required|integer',
|
'id' => 'required|integer',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -151,8 +152,9 @@ private function getModelClass($type)
|
|||||||
'music' => \App\Models\Music::class,
|
'music' => \App\Models\Music::class,
|
||||||
'media' => \App\Models\Media::class,
|
'media' => \App\Models\Media::class,
|
||||||
'breathing-template' => \App\Models\BreathingTemplate::class,
|
'breathing-template' => \App\Models\BreathingTemplate::class,
|
||||||
|
'playlist' => \App\Models\MusicPlaylist::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $models[$type] ?? null;
|
return $models[$type] ?? null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\SubCategory;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class SubCategoryController extends Controller
|
||||||
|
{
|
||||||
|
public function index(Request $request, $categoryId = null)
|
||||||
|
{
|
||||||
|
$query = SubCategory::with('category')->withCount('media');
|
||||||
|
|
||||||
|
$categoryId = $categoryId ?? $request->input('category_id');
|
||||||
|
|
||||||
|
if ($categoryId) {
|
||||||
|
$query->where('category_id', $categoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(
|
||||||
|
$query->orderBy('name')->get()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$data = $request->validate([
|
||||||
|
'category_id' => 'required|exists:categories,id',
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$existing = SubCategory::where('category_id', $data['category_id'])
|
||||||
|
->where('name', $data['name'])
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($existing) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'A subcategory with this name already exists in this category',
|
||||||
|
'errors' => ['name' => ['The subcategory name must be unique within this category.']],
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
$subCategory = SubCategory::create($data);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Subcategory created successfully',
|
||||||
|
'sub_category' => $subCategory->load('category'),
|
||||||
|
], 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show($id)
|
||||||
|
{
|
||||||
|
$subCategory = SubCategory::with('category')->withCount('media')->findOrFail($id);
|
||||||
|
|
||||||
|
return response()->json($subCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request, $id)
|
||||||
|
{
|
||||||
|
$subCategory = SubCategory::findOrFail($id);
|
||||||
|
|
||||||
|
$data = $request->validate([
|
||||||
|
'category_id' => 'sometimes|exists:categories,id',
|
||||||
|
'name' => 'sometimes|string|max:255',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$categoryId = $data['category_id'] ?? $subCategory->category_id;
|
||||||
|
$name = $data['name'] ?? $subCategory->name;
|
||||||
|
|
||||||
|
$existing = SubCategory::where('category_id', $categoryId)
|
||||||
|
->where('name', $name)
|
||||||
|
->where('id', '!=', $subCategory->id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($existing) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'A subcategory with this name already exists in this category',
|
||||||
|
'errors' => ['name' => ['The subcategory name must be unique within this category.']],
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
$subCategory->update($data);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Subcategory updated successfully',
|
||||||
|
'sub_category' => $subCategory->load('category'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
$subCategory = SubCategory::findOrFail($id);
|
||||||
|
$subCategory->delete();
|
||||||
|
|
||||||
|
return response()->json(['message' => 'Subcategory deleted successfully']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,5 +12,10 @@ public function questions()
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Question::class);
|
return $this->hasMany(Question::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function subcategories()
|
||||||
|
{
|
||||||
|
return $this->hasMany(SubCategory::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
class Like extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'likes';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'user_id',
|
||||||
|
'likeable_id',
|
||||||
|
'likeable_type',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function user(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function likeable(): MorphTo
|
||||||
|
{
|
||||||
|
return $this->morphTo();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper methods
|
||||||
|
public static function getLikedItemsForUser($userId, $type = null)
|
||||||
|
{
|
||||||
|
$query = self::with('likeable')->where('user_id', $userId);
|
||||||
|
|
||||||
|
if ($type) {
|
||||||
|
$query->where('likeable_type', $type);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query->latest()->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isLikedByUser($userId, $likeableId, $likeableType)
|
||||||
|
{
|
||||||
|
return self::where([
|
||||||
|
'user_id' => $userId,
|
||||||
|
'likeable_id' => $likeableId,
|
||||||
|
'likeable_type' => $likeableType,
|
||||||
|
])->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLikeCount($likeableId, $likeableType)
|
||||||
|
{
|
||||||
|
return self::where([
|
||||||
|
'likeable_id' => $likeableId,
|
||||||
|
'likeable_type' => $likeableType,
|
||||||
|
])->count();
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
-3
@@ -6,14 +6,15 @@
|
|||||||
use App\Traits\HasRatings;
|
use App\Traits\HasRatings;
|
||||||
use App\Traits\HasComments;
|
use App\Traits\HasComments;
|
||||||
use App\Traits\HasSaves;
|
use App\Traits\HasSaves;
|
||||||
|
use App\Traits\HasLikes;
|
||||||
class Media extends Model
|
class Media extends Model
|
||||||
{
|
{
|
||||||
use HasRatings, HasComments,HasSaves;
|
use HasRatings, HasComments,HasSaves,HasLikes;
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'user_id',
|
'user_id',
|
||||||
'image_id',
|
'image_id',
|
||||||
'category_id',
|
'category_id',
|
||||||
|
'subcategory_id',
|
||||||
'title',
|
'title',
|
||||||
'caption',
|
'caption',
|
||||||
'type',
|
'type',
|
||||||
@@ -33,7 +34,11 @@ class Media extends Model
|
|||||||
'user_comment_id',
|
'user_comment_id',
|
||||||
'has_user_rated',
|
'has_user_rated',
|
||||||
'is_saved',
|
'is_saved',
|
||||||
'saved_count'
|
'saved_count',
|
||||||
|
'is_liked',
|
||||||
|
'likes_count',
|
||||||
|
'is_liked',
|
||||||
|
'likes_count',
|
||||||
];
|
];
|
||||||
public function image()
|
public function image()
|
||||||
{
|
{
|
||||||
@@ -44,6 +49,11 @@ public function category()
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Category::class);
|
return $this->belongsTo(Category::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function subCategory()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(SubCategory::class, 'subcategory_id');
|
||||||
|
}
|
||||||
public function tags()
|
public function tags()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Tag::class, 'media_tag');
|
return $this->belongsToMany(Tag::class, 'media_tag');
|
||||||
|
|||||||
@@ -11,10 +11,11 @@
|
|||||||
use App\Traits\HasRatings;
|
use App\Traits\HasRatings;
|
||||||
use App\Traits\HasComments;
|
use App\Traits\HasComments;
|
||||||
use App\Traits\HasSaves;
|
use App\Traits\HasSaves;
|
||||||
|
use App\Traits\HasLikes;
|
||||||
|
|
||||||
class Music extends Model
|
class Music extends Model
|
||||||
{
|
{
|
||||||
use HasFactory, HasRatings, HasComments , HasSaves;
|
use HasFactory, HasRatings, HasComments , HasSaves,HasLikes;
|
||||||
protected $table = 'music';
|
protected $table = 'music';
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +55,9 @@ public function tags(): BelongsToMany
|
|||||||
'user_comment_id',
|
'user_comment_id',
|
||||||
'has_user_rated' ,
|
'has_user_rated' ,
|
||||||
'is_saved',
|
'is_saved',
|
||||||
'saved_count'
|
'saved_count',
|
||||||
|
'is_liked',
|
||||||
|
'likes_count'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getUrlAttribute()
|
public function getUrlAttribute()
|
||||||
|
|||||||
@@ -5,8 +5,12 @@
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo; // ← Add this
|
use Illuminate\Database\Eloquent\Relations\BelongsTo; // ← Add this
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany; // ← Add this
|
use Illuminate\Database\Eloquent\Relations\HasMany; // ← Add this
|
||||||
|
use App\Traits\HasComments; // Add this
|
||||||
|
use App\Traits\HasLikes;
|
||||||
|
use App\Traits\HasSaves;
|
||||||
class MusicPlaylist extends Model
|
class MusicPlaylist extends Model
|
||||||
{
|
{
|
||||||
|
use HasComments, HasLikes, HasSaves;
|
||||||
protected $table = 'music_playlists';
|
protected $table = 'music_playlists';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
@@ -17,7 +21,16 @@ class MusicPlaylist extends Model
|
|||||||
'is_active' => 'boolean',
|
'is_active' => 'boolean',
|
||||||
'order' => 'integer',
|
'order' => 'integer',
|
||||||
];
|
];
|
||||||
|
protected $appends = [
|
||||||
|
'comments_count',
|
||||||
|
'has_user_commented',
|
||||||
|
'user_comment',
|
||||||
|
'user_comment_id',
|
||||||
|
'is_liked',
|
||||||
|
'likes_count',
|
||||||
|
'is_saved',
|
||||||
|
'saved_count'
|
||||||
|
];
|
||||||
public function category(): BelongsTo
|
public function category(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(MusicCategory::class, 'category_id');
|
return $this->belongsTo(MusicCategory::class, 'category_id');
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
class SubCategory extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'sub_categories';
|
||||||
|
|
||||||
|
protected $fillable = ['category_id', 'name'];
|
||||||
|
|
||||||
|
public function category(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Category::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function media(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Media::class, 'subcategory_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
// app/Traits/HasLikes.php
|
||||||
|
namespace App\Traits;
|
||||||
|
|
||||||
|
use App\Models\Like;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
|
|
||||||
|
trait HasLikes
|
||||||
|
{
|
||||||
|
public function likes(): MorphMany
|
||||||
|
{
|
||||||
|
return $this->morphMany(Like::class, 'likeable');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIsLikedAttribute()
|
||||||
|
{
|
||||||
|
if (!auth()->check()) return false;
|
||||||
|
|
||||||
|
return $this->likes()
|
||||||
|
->where('user_id', auth()->id())
|
||||||
|
->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLikesCountAttribute()
|
||||||
|
{
|
||||||
|
return $this->likes()->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toggleLike()
|
||||||
|
{
|
||||||
|
if ($this->getIsLikedAttribute()) {
|
||||||
|
return $this->removeLike();
|
||||||
|
} else {
|
||||||
|
return $this->addLike();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addLike()
|
||||||
|
{
|
||||||
|
if ($this->getIsLikedAttribute()) return false;
|
||||||
|
|
||||||
|
return Like::create([
|
||||||
|
'user_id' => auth()->id(),
|
||||||
|
'likeable_id' => $this->id,
|
||||||
|
'likeable_type' => get_class($this),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeLike()
|
||||||
|
{
|
||||||
|
if (!$this->getIsLikedAttribute()) return false;
|
||||||
|
|
||||||
|
return Like::where([
|
||||||
|
'user_id' => auth()->id(),
|
||||||
|
'likeable_id' => $this->id,
|
||||||
|
'likeable_type' => get_class($this),
|
||||||
|
])->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
+34
-7
@@ -3,6 +3,7 @@
|
|||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration
|
||||||
{
|
{
|
||||||
@@ -11,9 +12,22 @@
|
|||||||
*/
|
*/
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Schema::table('music', function (Blueprint $table) {
|
// Get the database driver
|
||||||
$table->integer('duration')->nullable()->change();
|
$driver = DB::connection()->getDriverName();
|
||||||
});
|
|
||||||
|
if ($driver === 'pgsql') {
|
||||||
|
// PostgreSQL: Use raw statement with USING clause
|
||||||
|
DB::statement('ALTER TABLE music ALTER COLUMN duration TYPE integer USING (duration::integer)');
|
||||||
|
|
||||||
|
Schema::table('music', function (Blueprint $table) {
|
||||||
|
$table->integer('duration')->nullable()->change();
|
||||||
|
});
|
||||||
|
} elseif ($driver === 'mysql') {
|
||||||
|
// MySQL: Can directly change column type
|
||||||
|
Schema::table('music', function (Blueprint $table) {
|
||||||
|
$table->integer('duration')->nullable()->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,8 +35,21 @@ public function up(): void
|
|||||||
*/
|
*/
|
||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
Schema::table('music', function (Blueprint $table) {
|
// Get the database driver
|
||||||
$table->string('duration')->nullable()->change();
|
$driver = DB::connection()->getDriverName();
|
||||||
});
|
|
||||||
|
if ($driver === 'pgsql') {
|
||||||
|
// PostgreSQL: Convert back to text
|
||||||
|
DB::statement('ALTER TABLE music ALTER COLUMN duration TYPE text USING (duration::text)');
|
||||||
|
|
||||||
|
Schema::table('music', function (Blueprint $table) {
|
||||||
|
$table->string('duration')->nullable()->change();
|
||||||
|
});
|
||||||
|
} elseif ($driver === 'mysql') {
|
||||||
|
// MySQL: Change back to string
|
||||||
|
Schema::table('music', function (Blueprint $table) {
|
||||||
|
$table->string('duration')->nullable()->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('likes', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('user_id')->constrained()->onDelete('cascade');
|
||||||
|
$table->morphs('likeable');
|
||||||
|
$table->timestamps();
|
||||||
|
$table->unique(['user_id', 'likeable_id', 'likeable_type']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('likes');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('sub_categories', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('category_id')->constrained('categories')->cascadeOnDelete();
|
||||||
|
$table->string('name');
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->unique(['category_id', 'name']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('sub_categories');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('media', function (Blueprint $table) {
|
||||||
|
$table->unsignedBigInteger('subcategory_id')->nullable()->after('category_id');
|
||||||
|
|
||||||
|
$table->foreign('subcategory_id')->references('id')->on('sub_categories')->nullOnDelete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('media', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['subcategory_id']);
|
||||||
|
$table->dropColumn('subcategory_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -15,12 +15,15 @@
|
|||||||
use App\Http\Controllers\ImageController;
|
use App\Http\Controllers\ImageController;
|
||||||
use App\Http\Controllers\MusicController;
|
use App\Http\Controllers\MusicController;
|
||||||
use App\Http\Controllers\MediaController;
|
use App\Http\Controllers\MediaController;
|
||||||
|
use App\Http\Controllers\CategoryController;
|
||||||
|
use App\Http\Controllers\SubCategoryController;
|
||||||
use App\Http\Controllers\MusicCategoryController;
|
use App\Http\Controllers\MusicCategoryController;
|
||||||
use App\Http\Controllers\MusicPlaylistController;
|
use App\Http\Controllers\MusicPlaylistController;
|
||||||
use App\Http\Controllers\RatingController;
|
use App\Http\Controllers\RatingController;
|
||||||
use App\Http\Controllers\CommentController;
|
use App\Http\Controllers\CommentController;
|
||||||
use App\Http\Controllers\MusicSubcategoryController;
|
use App\Http\Controllers\MusicSubcategoryController;
|
||||||
use App\Http\Controllers\SaveController;
|
use App\Http\Controllers\SaveController;
|
||||||
|
use App\Http\Controllers\LikeController;
|
||||||
|
|
||||||
Route::get('/test-hash', function() {
|
Route::get('/test-hash', function() {
|
||||||
$plain = 'amnk1380';
|
$plain = 'amnk1380';
|
||||||
@@ -157,6 +160,13 @@
|
|||||||
//add note to media
|
//add note to media
|
||||||
Route::post('/media/{id}/note', [MediaController::class, 'storeNote']);
|
Route::post('/media/{id}/note', [MediaController::class, 'storeNote']);
|
||||||
|
|
||||||
|
// Media categories
|
||||||
|
Route::apiResource('categories', CategoryController::class);
|
||||||
|
|
||||||
|
// Media sub categories
|
||||||
|
Route::get('sub-categories/by-category/{categoryId}', [SubCategoryController::class, 'index']);
|
||||||
|
Route::apiResource('sub-categories', SubCategoryController::class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Music Categories
|
// Music Categories
|
||||||
@@ -211,4 +221,15 @@
|
|||||||
Route::get('/my-saved', [SaveController::class, 'mySavedItems']);
|
Route::get('/my-saved', [SaveController::class, 'mySavedItems']);
|
||||||
Route::post('/check', [SaveController::class, 'checkSaved']);
|
Route::post('/check', [SaveController::class, 'checkSaved']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Like routes (only for music and media)
|
||||||
|
Route::prefix('likes')->group(function () {
|
||||||
|
Route::post('/like', [LikeController::class, 'like']);
|
||||||
|
Route::post('/unlike', [LikeController::class, 'unlike']);
|
||||||
|
Route::post('/toggle', [LikeController::class, 'toggleLike']);
|
||||||
|
Route::get('/my-liked', [LikeController::class, 'myLikedItems']);
|
||||||
|
Route::post('/check', [LikeController::class, 'checkLiked']);
|
||||||
|
Route::get('/top-liked', [LikeController::class, 'topLiked']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user