$carts * @property-read int|null $carts_count * @property-read ProductCategory|null $category * @property-read Collection $favoritedBy * @property-read int|null $favorited_by_count * @property-read Collection $images * @property-read int|null $images_count * * @method static Builder|Product active() * @method static Builder|Product newModelQuery() * @method static Builder|Product newQuery() * @method static Builder|Product query() * @method static Builder|Product whereActualPrice($value) * @method static Builder|Product whereCreatedAt($value) * @method static Builder|Product whereDescription($value) * @method static Builder|Product whereId($value) * @method static Builder|Product whereIsActive($value) * @method static Builder|Product whereListPrice($value) * @method static Builder|Product whereProductCategoryId($value) * @method static Builder|Product whereSlug($value) * @method static Builder|Product whereTitle($value) * @method static Builder|Product whereUpdatedAt($value) * * @mixin \Eloquent */ class Product extends Model { protected $fillable = [ 'title', 'slug', 'actual_price', 'list_price', 'description', 'product_category_id', ]; public function category(): BelongsTo { return $this->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'); } public function carts() { return $this->belongsToMany(Cart::class); } #[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', ]; } }