Search code examples
phplaravellaravel-5laravel-storage

Laravel's deleteDirectory ignores preserve flag


Looking at Laravel's 5.7 deleteDirectory method in the API, it has a preserve flag to just empty the directory in each case.

I want 4 dirs to be emptied working with Laravel 5.7:

$dirs = ['dir1', 'dir2', 'dir3', 'dir4'];
foreach ($dirs as $dir)
    Storage::deleteDirectory($dir, true);

The code is executed, but it also removes the dirs themselves, which is not the desired behaviour.

Also, method cleanDirectory of the API results in a Call to undefined method League\Flysystem\Filesystem::cleanDirectory error...

Any ideas?


Solution

  • You aren't using Illuminate Filesystem, you are using the PHP League of Extraordinary Packages Flystem (which I absolutely love).

    Here are the correct docs for the classes you are using.

    https://laravel.com/docs/5.6/filesystem#directories

    https://flysystem.thephpleague.com/docs/usage/filesystem-api/

    It doesn't appear that there is a preserve option.