FileByObjectResource.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. 'updated_by' => $this->updatedBy ? new UserProfileResource($this->updatedBy) : null,
  25. 'created_at' => (string) $this->created_at,
  26. 'updated_at' => (string) $this->updated_at,
  27. 'version' => $this->version,
  28. 'display_id'=>(string)$this->display_id,
  29. 'object_type'=>$this->object_type,
  30. 'object_id'=>$this->object_id,
  31. 'approval_status'=>$this->approval_status,
  32. 'naming_rule' => $this->namingRule ? new NamingRuleSimpleResource($this->namingRule) : null,
  33. 'naming_rules' => $this->naming_rules,
  34. 'doc_stage' => $this->doc_stage,
  35. 'doc_type' => $this->doc_type,
  36. 'bim_file' => $this->bimFile ? new BimFileResource($this->bimFile) : null,
  37. ];
  38. if ($this->is_bim == 1 && $this->bimFile && $this->bimFile->convert_status == BimFileConvertStatus::DONE->value) {
  39. $data['model_preview'] = true;
  40. }
  41. return $data;
  42. }
  43. }