belongsTo(ProductCategory::class, 'product_category_id'); } public function images(): HasMany { return $this->hasMany(ProductImage::class, 'product_id', 'id'); } public function favoritedBy(): BelongsToMany { return $this->belongsToMany(User::class, 'favorite_products'); } #[Scope] protected function active(Builder $query): Builder { return $query->where('is_active', true); } protected static function booted(): void { static::saving(function ($product) { if (empty($product->slug) || $product->isDirty('title')) { $product->slug = Str::slug($product->title); } }); } protected function casts() { return [ 'is_active' => 'boolean', ]; } }