Reputation: 377
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();
Upvotes: 19
Views: 27737
Reputation: 63
Delete a Folder with Storage or File Class
Storage::deleteDirectory($path);
Upvotes: 1
Reputation: 967
After much frustration I got the solution.
Use 'File' instead of 'Storage'
File::deleteDirectory($path);
Upvotes: 33
Reputation: 163748
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
Upvotes: 20