| 123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace App\Http\Resources;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- use Illuminate\Support\Facades\Storage;
- class EventResource extends JsonResource
- {
- public function toArray(Request $request): array
- {
- return [
- 'id' => $this->id,
- 'title' => $this->title,
- 'description' => $this->description,
- 'date' => $this->date?->format('Y-m-d'),
- 'time' => $this->time
- ? Carbon::parse($this->time)->format('H:i')
- : null,
- 'type' => $this->type,
- 'cover_path' => $this->cover_path,
- 'cover_url' => $this->cover_path
- ? Storage::disk('s3')->temporaryUrl($this->cover_path, now()->addHours(24))
- : null,
- 'order' => $this->order,
- 'media' => $this->whenLoaded('media', fn() => MediaResource::collection($this->media)),
- 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
- 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
- ];
- }
- }
|