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); } /** * Return the localized URL for a given locale. */ public function getLocalizedUrl(string $locale): string { $routeName = $locale === 'fr' ? 'product.show' : $locale . '.product.show'; return route($routeName, [ 'gammeSlug' => $this->gamme->getTranslation('slug', $locale), 'productSlug' => $this->getTranslation('slug', $locale), ]); } /** * toSitemapTag method * * @return Url|string|array */ public function toSitemapTag(): Url | string | array { $model = $this; $route = 'gammes.show'; $params = ['publishedProduct' => $model]; return SitemapHelper::generateUrl($route, $params, $model); } }