FileByObjectResource.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. 'object_type'=>$this->object_type,
  28. 'object_id'=>$this->object_id,
  29. 'approval_status'=>$this->approval_status,
  30. 'naming_rule' => new NamingRuleSimpleResource($this->namingRule),
  31. 'naming_rules' => $this->naming_rules,
  32. ];
  33. if ($this->is_bim == 1 && $this->bimFile && $this->bimFile->convert_status == BimFileConvertStatus::DONE->value) {
  34. $data['model_preview'] = true;
  35. }
  36. return $data;
  37. }
  38. }