Posts Learn Components Snippets Categories Tags Tools About

How to Delete Directory In Laravel Storage

Learn how to programmatically delete a directory and the file inside it using the Storage facade provided by Laravel.

Created on Sep 01, 2021


To delete a directory in the Laravel application you can make use of the "deleteDirectory()" method available from the Storage facade.

This method will delete the directory with all of its files so you must carefully ensure that you are deleting the right directory.


How to Specify Disk when Deleting Directory in Laravel

Since some Laravel applications will have multiple disks you can specify the disk to use like below.

Do note that you will have to execute the code to delete the directory. One way is to call an endpoint to do so.

Route::get('/delete-directory', function () {
Now when you visit the "/delete-directory" endpoint, the "path/to/directory" will get deleted.

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for How to Delete Directory In Laravel Storage


PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that are right for your project.

View Components

Sponsors 👑

+ Add Yours