FileDownloadResource.php 905 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use App\Models\Enums\BimFileConvertStatus;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. use Illuminate\Support\Facades\Storage;
  7. class FileDownloadResource extends JsonResource
  8. {
  9. /**
  10. * Transform the resource into an array.
  11. *
  12. * @return array<string, mixed>
  13. */
  14. public function toArray(Request $request): array
  15. {
  16. $data = [
  17. 'id' => $this->id,
  18. 'title' => $this->title,
  19. 'download_url' => Storage::url($this->pathname),
  20. 'extension' => $this->extension,
  21. 'size' => $this->size,
  22. 'version' => $this->version,
  23. ];
  24. if ($this->is_bim == 1 && $this->bimFile && $this->bimFile->convert_status == BimFileConvertStatus::DONE->value) {
  25. $data['model_preview'] = true;
  26. }
  27. return $data;
  28. }
  29. }