Posts Learn Components Snippets Categories Tags 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.

Snippets by

PostSrc poster


Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.

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's right for your project.

View Components

Other Code Snippets