40 lines
1.4 KiB
PHP
40 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Event\Resources;
|
|
|
|
use App\Domains\Event\Models\Event;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/** @mixin Event */
|
|
class EventResource extends JsonResource
|
|
{
|
|
/** @return array<string, mixed> */
|
|
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,
|
|
],
|
|
];
|
|
}
|
|
}
|