picture, "SplFileInfo")) { $product->picture = Utils::storeImage($product->picture, $product->getTable()); } }); static::updating(function (Product $product): void { if (is_a($product->picture, "SplFileInfo")) { $product->picture = Utils::storeImage($product->picture, $product->getTable()); } }); static::deleted(function (Product $product): void { if ($product->picture) { $urlPicture = public_path() . $product->picture; if ($urlPicture) { if (File::exists($urlPicture)) { File::delete($urlPicture); } } } // Delete des images de plus produit. $plusproduit = json_decode($product->plusproduit); foreach ($plusproduit as $plus) { $urlPicture = public_path() . $plus->url; if ($urlPicture) { if (File::exists($urlPicture)) { File::delete($urlPicture); } } } }); parent::boot(); } /** * Get the Range that owns the product. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function gamme() { return $this->belongsTo(Gamme::class); } }