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