Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

1.7 KB
Raw Blame
<?php

namespace HiEvents\Resources\Organizer;

use HiEvents\DomainObjects\OrganizerDomainObject;
use HiEvents\Resources\Event\EventResourcePublic;
use HiEvents\Resources\Image\ImageResource;
use HiEvents\Resources\Location\LocationPublicResource;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @mixin OrganizerDomainObject
 */
class OrganizerResourcePublic extends JsonResource
{
    public function toArray($request): array
    {
        return [
            'id' => $this->getId(),
            'name' => $this->getName(),
            'website' => $this->getWebsite(),
            'description' => $this->getDescription(),
            'slug' => $this->getSlug(),
            'status' => $this->getStatus(),
            'branding_removed' => $this->when(
                $this->getBrandingRemoved() !== null,
                fn () => (bool) $this->getBrandingRemoved(),
            ),
            'location' => $this->when(
                condition: $this->getLocationRecord() !== null,
                value: fn () => new LocationPublicResource($this->getLocationRecord()),
            ),
            'images' => $this->when(
                (bool) $this->getImages(),
                fn () => ImageResource::collection($this->getImages())
            ),
            'events' => $this->when(
                condition: ! is_null($this->getEvents()),
                value: fn () => EventResourcePublic::collection($this->getEvents())
            ),
            'settings' => $this->when(
                condition: ! is_null($this->getOrganizerSettings()),
                value: fn () => new OrganizerSettingsPublicResource($this->getOrganizerSettings())
            ),
        ];
    }
}