*/ public function toArray(Request $request): array { $socialMedia = $this->tenant->socialMedia->keyBy('code'); return [ 'id' => $this->id, 'title' => $this->name, 'location' => $this->address, 'dates' => $this->dates->map(fn ($eventDate): array => [ 'id' => $eventDate->id, 'date' => $eventDate->date->format('Y-m-d'), 'start_time' => substr($eventDate->time_start, 0, 5), 'end_time' => substr($eventDate->time_end, 0, 5), ])->values(), 'social_media' => $this->tenant->socialMedia->map(fn ($item): array => [ 'code' => $item->code, 'url' => $item->pivot->url, 'orden' => $item->pivot->orden, ])->values(), 'contact' => [ 'whatsapp_url' => $socialMedia->get('whatsapp')?->pivot->url, 'instagram_url' => $socialMedia->get('instagram')?->pivot->url, 'facebook_url' => $socialMedia->get('facebook')?->pivot->url, ], ]; } }