Files
fotospiel-app/app/Http/Resources/Tenant/EventResource.php

42 lines
1.7 KiB
PHP

<?php
namespace App\Http\Resources\Tenant;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class EventResource extends JsonResource
{
public function toArray(Request $request): array
{
$tenantId = $request->attributes->get('tenant_id');
$showSensitive = $this->tenant_id === $tenantId;
$settings = is_array($this->settings) ? $this->settings : [];
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'description' => $this->description,
'event_date' => $this->date ? $this->date->toISOString() : null,
'location' => $this->location,
'max_participants' => $this->max_participants,
'current_participants' => $showSensitive ? ($this->photos_count ?? null) : null,
'public_url' => $settings['public_url'] ?? null,
'custom_domain' => $showSensitive ? ($settings['custom_domain'] ?? null) : null,
'theme_color' => $settings['theme_color'] ?? null,
'status' => $this->status ?? 'draft',
'is_active' => (bool) ($this->is_active ?? false),
'features' => $settings['features'] ?? [],
'event_type_id' => $this->event_type_id,
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
'photo_count' => $this->photos_count ?? 0,
'like_count' => $this->whenLoaded('photos', fn () => $this->photos->sum('likes_count'), 0),
'is_public' => $this->status === 'published',
'public_share_url' => null,
'qr_code_url' => null,
];
}
}