fix
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Traits\StoresUploads;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
@@ -12,6 +13,8 @@
|
||||
*/
|
||||
abstract class CatalogController extends Controller
|
||||
{
|
||||
use StoresUploads;
|
||||
|
||||
/** @return class-string<\Illuminate\Database\Eloquent\Model> */
|
||||
abstract protected function modelClass(): string;
|
||||
|
||||
@@ -52,7 +55,7 @@ public function store(Request $request)
|
||||
|
||||
foreach ($this->fileFields() as $field => $config) {
|
||||
$attributes[$config['column']] = $request->hasFile($field)
|
||||
? $request->file($field)->store($config['folder'], 'public')
|
||||
? $this->storeUpload($request->file($field), $config['folder'])
|
||||
: null;
|
||||
}
|
||||
|
||||
@@ -82,7 +85,7 @@ public function update(Request $request, $id)
|
||||
if ($item->{$config['column']}) {
|
||||
Storage::disk('public')->delete($item->{$config['column']});
|
||||
}
|
||||
$item->{$config['column']} = $request->file($field)->store($config['folder'], 'public');
|
||||
$item->{$config['column']} = $this->storeUpload($request->file($field), $config['folder']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@
|
||||
use App\Models\SubCategory;
|
||||
use App\Models\Tag;
|
||||
use App\Traits\HandlesImageUpload;
|
||||
use App\Traits\StoresUploads;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class MediaController extends Controller
|
||||
{
|
||||
use HandlesImageUpload;
|
||||
use HandlesImageUpload, StoresUploads;
|
||||
|
||||
// CREATE media
|
||||
public function store(Request $request)
|
||||
@@ -41,19 +42,23 @@ public function store(Request $request)
|
||||
|
||||
$path = null;
|
||||
if ($request->hasFile('file')) {
|
||||
$path = $request->file('file')->store('media', 'public');
|
||||
$path = $this->storeUpload($request->file('file'), 'media');
|
||||
}
|
||||
|
||||
// An uploaded image file takes precedence over a provided image_id.
|
||||
$imageId = $this->uploadedImageId($request) ?? ($data['image_id'] ?? null);
|
||||
|
||||
// When a file is uploaded, expose its public URL as external_url too
|
||||
// (older front-end versions read external_url for the playable source).
|
||||
$externalUrl = $path ? asset('storage/' . $path) : ($data['external_url'] ?? null);
|
||||
|
||||
$media = Media::create([
|
||||
'user_id' => auth()->id(),
|
||||
'title' => $data['title'],
|
||||
'caption' => $data['caption'] ?? null,
|
||||
'type' => $data['type'],
|
||||
'file_path' => $path,
|
||||
'external_url' => $data['external_url'] ?? null,
|
||||
'external_url' => $externalUrl,
|
||||
'image_id' => $imageId,
|
||||
'duration' => $data['duration'] ?? null,
|
||||
'visibility' => $data['visibility'] ?? 'public',
|
||||
@@ -488,7 +493,9 @@ public function update(Request $request, $id)
|
||||
// --- handle file replace ---
|
||||
if ($request->hasFile('file')) {
|
||||
Storage::disk('public')->delete($media->file_path);
|
||||
$data['file_path'] = $request->file('file')->store('media', 'public');
|
||||
$data['file_path'] = $this->storeUpload($request->file('file'), 'media');
|
||||
// Keep external_url pointing at the newly uploaded file for the old front-end.
|
||||
$data['external_url'] = asset('storage/' . $data['file_path']);
|
||||
}
|
||||
|
||||
// --- Prepare update data ---
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
use App\Models\MusicPlaylist;
|
||||
use App\Models\Music;
|
||||
use App\Traits\HandlesImageUpload;
|
||||
use App\Traits\StoresUploads;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class MusicController extends Controller
|
||||
{
|
||||
use HandlesImageUpload;
|
||||
use HandlesImageUpload, StoresUploads;
|
||||
|
||||
// Add this new method to your MusicController
|
||||
public function getAllMusic()
|
||||
@@ -160,8 +161,8 @@ public function store(Request $request)
|
||||
], 422);
|
||||
}
|
||||
|
||||
$path = $file->store('music', 'public');
|
||||
|
||||
$path = $this->storeUpload($file, 'music');
|
||||
|
||||
if (!$path) {
|
||||
return response()->json([
|
||||
'message' => 'Failed to store the file'
|
||||
@@ -248,7 +249,7 @@ public function update(Request $request, $id)
|
||||
if ($request->hasFile('file')) {
|
||||
// Delete old file
|
||||
Storage::disk('public')->delete($music->file_path);
|
||||
$path = $request->file('file')->store('music', 'public');
|
||||
$path = $this->storeUpload($request->file('file'), 'music');
|
||||
$music->file_path = $path;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user