What is the proper syntax when deleting a folder with files in laravel 5.2?
Here is my syntax when deleting the folder from the DB and DIR
$folder = Folder::find($id);
$folder_path = storage_path('locker').'/'. $folder->folder_title;
$folder->delete();
`rmdir($folder_path);`
\Session::flash('success', 'Folder Deleted!');
return back();
One way to delete a file from the public directory in Laravel is to use the Storage facade. To delete a file, you will need to follow the following steps: Step 1: Check to ensure that the folder and file exist. Step 2: Delete the required file.
The public_path() is a method Laravel uses to fetch the folder passed as a parameter to the path of the directory. The Storage facade grants access to the file system of the application so that the deleteDirectory() method can delete the specified directory.
To delete a directory in the Laravel application you can make use of the "deleteDirectory()" method available from the Storage facade. <? php Storage::deleteDirectory($directory); This method will delete the directory with all of its files so you must carefully ensure that you are deleting the right directory.
Your answer You could use PHP's unlink() method just as @Khan suggested. But if you want to do it the Laravel way, use the File::delete() method instead. $files = array($file1, $file2); File::delete($files);
After much frustration I got the solution.
Use 'File' instead of 'Storage'
File::deleteDirectory($path);
The deleteDirectory may be used to remove a directory and all of its files
Storage::deleteDirectory($directory);
https://laravel.com/docs/5.3/filesystem#directories
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