How could I delete a directory from the public folder? Right now I try this:
Storage::deleteDirectory($directory);
But that looks in the storage folder?
You can use Illuminate\Filesystem\Filesystem
for this. Laravel provides the File
facade for easy access:
File::deleteDirectory(public_path('path/to/folder'));
The method will return true
if it succeeds, false
if it fails.
You can use this:
$path = 'upload/pic/foldername/';
if (\File::exists($path)) \File::deleteDirectory($path);
foldername is deleting with all files in it.
To be accessible by Storage you should define the filesystem name in config/filesystems
and be sure to have the right permissions to be able to what you want to do.
Then something like Storage::deleteDirectory($directory);
assuming that $directory
is something you got properly from the corresponding resource.
Read the docs here
You can use File instead of Storage. Try this one:
File::deleteDirectory(public_path($directory));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With