简体   繁体   中英

Deleting a folder with files in Laravel

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();

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

Delete a Folder with Storage or File Class

Storage::deleteDirectory($path);

Laracast

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM