Reputation: 175
I cannot delete file by using laravel Storage::delete
fuction.
My image store code is :
$logoPath = $request->file('logo')->store('images','public');
It store image at
storage/app/public/images/0HHJ5DygYUXuLC5dgu14KJTPvCEaxhISV8tpb4Pq.png
I use Storage::delete('/images/0HHJ5DygYUXuLC5dgu14KJTPvCEaxhISV8tpb4Pq.png');
to delete it. But it not working;
What I have tried is:
Storage::delete(asset('storage/images/0HHJ5DygYUXuLC5dgu14KJTPvCEaxhISV8tpb4Pq.png'));
Storage::delete(storage_path('images/0HHJ5DygYUXuLC5dgu14KJTPvCEaxhISV8tpb4Pq.png'));`
Even I try to delete some picture at public folder. It's not working.
Storage::delete(public_path('images/logo3.png'));
Did I do something wrong?
Upvotes: 2
Views: 2008
Reputation: 10111
The delete method accepts a single filename to remove from the disk:
Storage::delete('public/images/filename.png');
Upvotes: 0
Reputation: 2267
this is what works for me, hopefully it works for you too:
Storage::delete('public/images/0HHJ5DygYUXuLC5dgu14KJTPvCEaxhISV8tpb4Pq.png');
Upvotes: 4
Reputation: 501
This is the php way of deleting a file. unlink() function.
$file = $request->input('filename');
unlink(storage_path('app/public/images/' . $file));
Upvotes: -1