Laravel

# Clear a file directory using Filesystem in Laravel

Published on September 28th, 2020

I was working on a project that dealt with generating large .zip exports and as a result, the storage/exports directory, which was used to store all the .zip exports, ended up going all the way up to a whopping size of 10 gigabytes! 😮

I resolved it by calling the Filesystem package in my controller:


use Illuminate\Filesystem\Filesystem;



Then simply, create a new instance and define the directory you wanted to clear:


$folder = new Filesystem;$folder->cleanDirectory('storage/exports');



Hope this helps you out!