FileByObjectResource.php 808 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. use Illuminate\Support\Facades\Storage;
  6. class FileByObjectResource extends JsonResource
  7. {
  8. /**
  9. * Transform the resource into an array.
  10. *
  11. * @return array<string, mixed>
  12. */
  13. public function toArray(Request $request): array
  14. {
  15. return [
  16. 'id' => $this->id,
  17. 'title' => $this->title,
  18. 'extension' => $this->extension,
  19. 'download_url' => Storage::url($this->pathname),
  20. 'size' => $this->size,
  21. 'created_by' => $this->createdBy?new UserProfileResource($this->createdBy):null,
  22. 'created_at' => (string)$this->created_at,
  23. 'version' => $this->version,
  24. ];
  25. }
  26. }