'date', 'production_date' => 'date', 'alcohol_percentage' => 'decimal:2', 'price_per_bottle' => 'decimal:2', 'bottle_volume' => 'decimal:3', ]; /** * Bootstrap the model and its traits. */ protected static function boot() { parent::boot(); // Automatically delete the wine image when the wine is deleted static::deleting(function ($wine) { if ($wine->image_url && Storage::disk('public')->exists($wine->image_url)) { Storage::disk('public')->delete($wine->image_url); } }); } /** * Get the grape variety for this wine. */ public function grapeVariety(): BelongsTo { return $this->belongsTo(GrapeVariety::class, 'grape_variety_id'); } /** * Get the wine production records for this wine. */ public function wineProductions(): HasMany { return $this->hasMany(WineProduction::class, 'wine_id'); } /** * Get the harvests used in this wine production (many-to-many through wine_productions). */ public function harvests(): BelongsToMany { return $this->belongsToMany(Harvest::class, 'wine_productions', 'wine_id', 'harvest_id') ->withPivot('consumed_weight', 'blend_percentage') ->withTimestamps(); } }