$this->lot_number, 'produced_at' => $this->produced_at?->toDateString(), 'expires_at' => $this->expires_at?->toDateString(), 'product' => [ 'name' => $this->product->title, 'description' => $this->product->description, ], 'recipe' => [ 'name' => $this->recipe->name, ], 'spices' => $this->recipe->spices->map(function ($spice) { $origin = $this->origins->firstWhere('spice_id', $spice->id); return [ 'name' => $spice->name, 'percentage' => (float) $spice->pivot->amount_in_percent, 'origin' => $origin ? [ 'country' => $origin->origin_country, 'farmer' => $origin->farmer, 'supplier' => $origin->supplier?->name, 'notes' => $origin->notes, ] : null, ]; })->values(), ]; } }