12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Http\Resources\API;
- use App\Libraries\BIM\BIMFactory;
- use App\Models\Enums\BimFileConvertStatus;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- use Illuminate\Support\Facades\Storage;
- class FileByObjectResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @return array<string, mixed>
- */
- public function toArray(Request $request): array
- {
- $data = [
- 'id' => $this->id,
- 'title' => $this->title,
- 'extension' => $this->extension,
- 'download_url' => Storage::url($this->pathname),
- 'size' => $this->size,
- 'created_by' => $this->createdBy ? new UserProfileResource($this->createdBy) : null,
- 'updated_by' => $this->updatedBy ? new UserProfileResource($this->updatedBy) : null,
- 'created_at' => (string) $this->created_at,
- 'updated_at' => (string) $this->updated_at,
- 'version' => $this->version,
- 'display_id'=>(string)$this->display_id,
- 'object_type'=>$this->object_type,
- 'object_id'=>$this->object_id,
- 'approval_status'=>$this->approval_status,
- 'naming_rule' => $this->namingRule ? new NamingRuleSimpleResource($this->namingRule) : null,
- 'naming_rules' => $this->naming_rules,
- 'doc_stage' => $this->doc_stage,
- 'doc_type' => $this->doc_type,
- 'bim_file' => $this->bimFile ? new BimFileResource($this->bimFile) : null,
- ];
- if ($this->is_bim == 1 && $this->bimFile && $this->bimFile->convert_status == BimFileConvertStatus::DONE->value) {
- $data['model_preview'] = true;
- }
- return $data;
- }
- }
|