48 lines
1.9 KiB
PHP
48 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Ticketing\Event\Resources;
|
|
|
|
use App\Domains\Ticketing\Event\Services\EventDateGroupingService;
|
|
use App\Domains\Ticketing\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->socialMedia->keyBy('code');
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'title' => $this->title,
|
|
'subtitle' => $this->subtitle,
|
|
'description' => $this->description,
|
|
'location' => $this->location,
|
|
'exact_location' => $this->exact_location,
|
|
'date_text' => $this->date_text,
|
|
'published_at' => $this->published_at?->toIso8601String(),
|
|
'attachment_id' => $this->attachment_id,
|
|
'allow_ticket_refund' => $this->tenant->allow_ticket_refund,
|
|
'allow_ticket_total_refund' => $this->tenant->allow_ticket_total_refund,
|
|
'allow_ticket_partial_refund' => $this->tenant->allow_ticket_partial_refund,
|
|
'ticket_partial_refund_percentage' => $this->tenant->ticket_partial_refund_percentage,
|
|
'dates' => EventDateResource::collection(
|
|
app(EventDateGroupingService::class)->group($this->dates)
|
|
),
|
|
'social_media' => $this->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,
|
|
],
|
|
];
|
|
}
|
|
}
|