Laravel 5.3: remove image from storage

I have a method that deletes the artwork and image it owns, but I cannot delete the image.

Where am I going wrong?

public function deleteProduct($ids)
{
    foreach ($ids as $id => $value) {
        $product = Product::find($id);
        $productImage = $product->image_path;
        if ($productImage) {
            Storage::delete($productImage);
            $product->destroy($id);
        }
    }
}

      

I have a symbolic link between a store and a shared folder.

Below the storage images are located, for example, - storage / app / public / images / products / 4 / image.png

In the public section - public / storage / images / products / 4 / imagep.png

The file path is stored in the database as - / storage / images / products / 4 / ACTCMRcYlWR8Bn3ZxoJ7bpiDJ7.png

+3


source to share


1 answer


I had to add the "/ storage" part of the path and add "/ public".

$productImage = str_replace('/storage', '', $product->image_path);



Storage::delete('/public' . $productImage);

+2


source







All Articles