*/ public function toArray(Request $request): array { if ($this->resource === null) { return [ 'id' => null, 'name' => 'Comida', 'variants' => [], ]; } return [ 'id' => $this->id, 'name' => $this->nombre, 'variants' => $this->variants->map(function ($variant): array { $values = $variant->selectionValues(); $eventDate = $variant->selectedEventDates()->first(); return [ 'id' => $variant->id, 'event_date_id' => $eventDate?->id, 'event_date' => $eventDate?->date?->format('Y-m-d'), 'schedule' => $values->get('horario'), 'service' => $values->get('servicio'), 'description' => $variant->descripcion, 'stock' => $variant->inventory->real_stock, 'price' => number_format($variant->getPrice(), 2, '.', ''), ]; })->values(), ]; } }