fix
This commit is contained in:
@@ -500,7 +500,9 @@ public function update(Request $request, $id)
|
|||||||
|
|
||||||
// --- handle file replace ---
|
// --- handle file replace ---
|
||||||
if ($request->hasFile('file')) {
|
if ($request->hasFile('file')) {
|
||||||
|
if ($media->file_path) {
|
||||||
Storage::disk('public')->delete($media->file_path);
|
Storage::disk('public')->delete($media->file_path);
|
||||||
|
}
|
||||||
$data['file_path'] = $this->storeUpload($request->file('file'), 'media');
|
$data['file_path'] = $this->storeUpload($request->file('file'), 'media');
|
||||||
// Keep external_url pointing at the newly uploaded file for the old front-end.
|
// Keep external_url pointing at the newly uploaded file for the old front-end.
|
||||||
$data['external_url'] = asset('storage/' . $data['file_path']);
|
$data['external_url'] = asset('storage/' . $data['file_path']);
|
||||||
@@ -575,7 +577,9 @@ public function destroy($id)
|
|||||||
->where('user_id', auth()->id())
|
->where('user_id', auth()->id())
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
|
if ($media->file_path) {
|
||||||
Storage::disk('public')->delete($media->file_path);
|
Storage::disk('public')->delete($media->file_path);
|
||||||
|
}
|
||||||
|
|
||||||
$media->delete();
|
$media->delete();
|
||||||
|
|
||||||
|
|||||||
@@ -248,7 +248,9 @@ public function update(Request $request, $id)
|
|||||||
|
|
||||||
if ($request->hasFile('file')) {
|
if ($request->hasFile('file')) {
|
||||||
// Delete old file
|
// Delete old file
|
||||||
|
if ($music->file_path) {
|
||||||
Storage::disk('public')->delete($music->file_path);
|
Storage::disk('public')->delete($music->file_path);
|
||||||
|
}
|
||||||
$path = $this->storeUpload($request->file('file'), 'music');
|
$path = $this->storeUpload($request->file('file'), 'music');
|
||||||
$music->file_path = $path;
|
$music->file_path = $path;
|
||||||
}
|
}
|
||||||
@@ -334,7 +336,9 @@ public function show($id)
|
|||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
$music = Music::where('id', $id)->where('user_id', auth()->id())->firstOrFail();
|
$music = Music::where('id', $id)->where('user_id', auth()->id())->firstOrFail();
|
||||||
|
if ($music->file_path) {
|
||||||
Storage::disk('public')->delete($music->file_path);
|
Storage::disk('public')->delete($music->file_path);
|
||||||
|
}
|
||||||
$music->delete();
|
$music->delete();
|
||||||
|
|
||||||
return response()->json(['message' => 'Music deleted successfully']);
|
return response()->json(['message' => 'Music deleted successfully']);
|
||||||
|
|||||||
Reference in New Issue
Block a user