Reputation: 320
I am trying to delete the mp3 file from my local folder but unfortunately, it's not deleting please help me how to do that thanks?
controller
public function destroy(Request $request)
{
$hamdnaat = HamdoNaat::findOrFail($request->deleteId);
// apply your conditional check here
if (false) {
$response['error'] = 'This hamdnaat has something assigned to it.';
return response()->json($response, 409);
} else {
Storage::disk('audiofile')->delete($hamdnaat);
$response = $hamdnaat->delete();
// form helpers.php
logAction($request);
return response()->json($response, 200);
}
}
filesystem.php
'audiofile' => [
'driver' => 'local',
'root' => public_path('uploads/audio'),
'url' => env('APP_URL').'/uploads/audio',
'visibility' => 'public',
],
Upvotes: 0
Views: 130
Reputation: 3411
You need to give the file name to the delete function when you try deleting a file. So use
Storage::disk('audiofile')->delete($hamdnaat['name']);
If the name field doesn't include the extension, make sure you add it.
Storage::disk('audiofile')->delete($hamdnaat['name'] + '.mp3');
Upvotes: 2