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

Alewa's avatar
Level 2

I am having Attempt to read property \"product_image\" on bool in my laravel 10 api

I am getting this error Attempt to read property \"product_image\" on bool when i try to delete image from the database and also delete it from my storage folder. My api code is able to delete the image from the database but is not able to delete the image in the storage folder.

ProductController.php file

0 likes
3 replies
Snapey's avatar

you are trying to get the image path AFTER you deleted the model.

In adition, you are treating the boolean that comes from the delete as the model

Snapey's avatar
Snapey
Best Answer
Level 122
public function deleteProductImage($id)
    {
        $product_image = ProductImage::findorfail($id);

        if (!empty($product_image->product_image)) {
            Storage::disk('public')->deleteDirectory(dirname($product_image->product_image));
        }

        $product_image->delete();

        return [
            'message' => 'Product Image Deleted Successfully'
        ];
    }

Please or to participate in this conversation.