FileByObjectResource.php 1.1 KB

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