where('codigo', 'onticket')->firstOrFail(); $events = [ [ 'title' => '[Prueba] Noche de Música en Vivo', 'category' => 'Música', 'subtitle' => 'Una noche para cantar y bailar', 'description' => 'Evento de prueba para explorar la cartelera de OnTicket.', 'location' => 'Teatro Broadway, Rosario', 'image' => 'live-music.avif', 'weeks_from_now' => [2], 'time_start' => '21:00:00', 'time_end' => '23:30:00', ], [ 'title' => '[Prueba] Festival de Sabores', 'category' => 'Otros', 'subtitle' => 'Gastronomía y música para toda la familia', 'description' => 'Evento de prueba con dos jornadas disponibles.', 'location' => 'Parque de España, Rosario', 'image' => 'food-festival.avif', 'weeks_from_now' => [3, 3], 'day_offsets' => [0, 1], 'time_start' => '12:00:00', 'time_end' => '20:00:00', ], [ 'title' => '[Prueba] Stand Up en el Centro', 'category' => 'Teatro', 'subtitle' => 'Humor para compartir', 'description' => 'Evento de prueba para visualizar distintas propuestas.', 'location' => 'Centro Cultural La Comedia, Rosario', 'image' => 'stand-up.avif', 'weeks_from_now' => [4], 'time_start' => '20:30:00', 'time_end' => '22:00:00', ], ]; DB::transaction(function () use ($tenant, $events): void { foreach ($events as $definition) { $event = $tenant->events()->firstOrCreate( ['title' => $definition['title']], [ 'subtitle' => $definition['subtitle'], 'description' => $definition['description'], 'location' => $definition['location'], 'published_at' => now(), 'event_category_id' => $tenant->eventCategories() ->where('nombre', $definition['category'])->value('id'), ], ); if ($event->event_category_id === null) { $event->update(['event_category_id' => $tenant->eventCategories() ->where('nombre', $definition['category'])->value('id')]); } if ($event->attachment_id === null) { $path = public_path(self::IMAGE_DIRECTORY.'/'.$definition['image']); if (! is_file($path)) { throw new RuntimeException("Image not found at path: {$path}"); } $attachment = $this->attachmentService->store( new UploadedFile($path, $definition['image'], 'image/avif', null, true), 'tenants/onticket/events', ); $event->update(['attachment_id' => $attachment->id]); } if ($event->dates()->exists()) { continue; } foreach ($definition['weeks_from_now'] as $index => $weeks) { $date = now()->startOfDay()->addWeeks($weeks) ->addDays($definition['day_offsets'][$index] ?? 0); $event->dates()->create([ 'tenant_code' => $tenant->codigo, 'date' => $date->toDateString(), 'time_start' => $definition['time_start'], 'time_end' => $definition['time_end'], ]); } } }); } }