EventResource.php 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Http\Resources;
  3. use Carbon\Carbon;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. use Illuminate\Support\Facades\Storage;
  7. class EventResource extends JsonResource
  8. {
  9. public function toArray(Request $request): array
  10. {
  11. return [
  12. 'id' => $this->id,
  13. 'title' => $this->title,
  14. 'description' => $this->description,
  15. 'date' => $this->date?->format('Y-m-d'),
  16. 'time' => $this->time
  17. ? Carbon::parse($this->time)->format('H:i')
  18. : null,
  19. 'type' => $this->type,
  20. 'cover_path' => $this->cover_path,
  21. 'cover_url' => $this->cover_path
  22. ? Storage::disk('s3')->temporaryUrl($this->cover_path, now()->addHours(24))
  23. : null,
  24. 'order' => $this->order,
  25. 'media' => $this->whenLoaded('media', fn() => MediaResource::collection($this->media)),
  26. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  27. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  28. ];
  29. }
  30. }