feat: Implement event management functionality with API endpoints and validation
This commit is contained in:
39
app/Domains/Event/Resources/EventResource.php
Normal file
39
app/Domains/Event/Resources/EventResource.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user