*/ protected $fillable = [ 'label', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = []; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted(): void { static::creating(function (self $productModel) { }); static::updating(function (self $productModel) { }); static::updated(function (self $productModel) { }); static::deleted(function (self $productModel) { }); } // * METHODS /** * Display a listing of the resource. * * @param string|null $slug * @return array */ public static function getProductsViewsByRange(string|null $slug = null): array { /** FIXME: replace 'first-range' by the first Range slug publicated with order by ASC. */ $rangeSlug = !is_null($slug) ? $slug : "first-range"; /** FIXME: replace this part of 'productModels' values by products associated to the range (limit 6, random). */ $productModels = []; for ($i = 0; $i < 5; $i++) { $productModels[] = (object)[ "name" => "Produit $i de la gamme $rangeSlug", 'packaging' => Vite::asset('resources/assets/images/tmp/packaging.png'), 'packaging_alt' => "lorem ipsum", 'packaging_title' => "lorem ipsum", 'picture' => Vite::asset('resources/assets/images/tmp/product-picture.png'), 'picture_alt' => "lorem ipsum", 'picture_title' => "lorem ipsum", 'tag' => Vite::asset('resources/assets/images/tmp/product-tag.png'), 'tag_alt' => "lorem ipsum", 'tag_title' => "lorem ipsum", 'isFavorite' => ($i % 2) ? true : false, 'isNew' => ($i % 2) ? false : true, ]; } foreach ($productModels as $productModel) { $productViews[] = view('fo.partials.product-card', compact('productModel'))->render(); } //end foreach return $productViews; } // * RELATIONSHIPS /** * Get all of the ranges that are assigned this product. * * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ public function ranges(): MorphToMany { return $this->morphedByMany(Range::class, 'productable'); } /** * Get all of the subranges that are assigned this product. * * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ public function subranges(): MorphToMany { return $this->morphedByMany(Subrange::class, 'productable'); } /** * Get all of the meats that are assigned this product. * * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ public function meats(): MorphToMany { return $this->morphedByMany(Meat::class, 'productable'); } /** * Get all of the submeats that are assigned this product. * * @return \Illuminate\Database\Eloquent\Relations\MorphToMany */ public function submeats(): MorphToMany { return $this->morphedByMany(Submeat::class, 'productable'); } }