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

mudzao's avatar

Storage::exists returns false

Hi, i'm writing a section in my product controller that checks if the old product image exist and then delete it before updating with the new image path

        $newImageName = $product->id.'-'.$request->image->getClientOriginalName();
        $newImage = $request->image->move(public_path("images/product/$product->id"),$newImageName);
        $oldPath = public_path("images/product/$product->id/").$product->image;

        if (Storage::exists(public_path("images/product/$product->id/").$product->image)){
            dd('File is exists.');
        } else {
            dd('File not exist');
        }

$oldPath value ="C:\laragon\www\mini\public\images/product/11/11-20119342_10_400.jpg" and it confirm exists. but it always returns fail.

i have no issue uploading the new file in the which will be in "C:\laragon\www\mini\public\images/product/11\11-20112633_01_400.jpg"

is it because of the \ and / since i'm using windows?

0 likes
2 replies
Sinnbeck's avatar

Be aware that Storage::exists() uses the default disks, storage path.. Check your filesystems.php file to see what the path is for the default disk. My suggestion is to create a new disk, and set its path to public_path("images/product/) and then use that.

2 likes
mudzao's avatar

hi, ive decided to use File instead and it works. thans!

Please or to participate in this conversation.