Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Presto's avatar

Storage S3 deleteDirectory Not Working?

Digging in to the docs and looking at the filesystem it looks like there is a function called deleteDirectory but when I try and use it, it does not work.

http://laravel.com/api/5.0/Illuminate/Contracts/Filesystem/Cloud.html#method_deleteDirectory

Is this a working function?

Here is my code:

public function destroy($id)
{
    // Remove property photos from AWS S3
    if(Storage::disk('s3')->exists('property/' . $id))
    {
        Storage::disk('s3')->deleteDirectory('property/' . $id);
    }
}
0 likes
1 reply
Presto's avatar
Presto
OP
Best Answer
Level 6

Ok it was how I was doing my if statement, the following worked:

public function destroy($id)
{
    // Remove property photos from AWS S3
    if(count(Storage::disk('s3')->exists('property/' . $id)) > 0)
    {
        Storage::disk('s3')->deleteDirectory('property/' . $id);
    }
}
2 likes

Please or to participate in this conversation.