FolderDetailResource.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Http\Resources\API;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class FolderDetailResource extends JsonResource
  6. {
  7. /**
  8. * Transform the resource into an array.
  9. *
  10. * @return array<string, mixed>
  11. */
  12. public function toArray(Request $request): array
  13. {
  14. return [
  15. 'id' => $this->id,
  16. 'object_type' => $this->object_type,
  17. 'object_id' => $this->object_id,
  18. 'name' => $this->name,
  19. 'parent_id' => $this->parent_id,
  20. 'sequence' => $this->sequence,
  21. 'created_at' => (string)$this->created_at,
  22. 'updated_at' => (string)$this->updated_at,
  23. 'created_by' => $this->createdBy ? new UserProfileResource($this->createdBy) : null,
  24. 'updated_by' => $this->updatedBy ? new UserProfileResource($this->updatedBy) : null,
  25. 'type' => 'folder',
  26. 'itemCount' => $this->children()->count() + $this->files()->where('is_latest_version', 1)->count(),
  27. 'uniId' => 'folder_' . $this->id,
  28. 'display_id'=>(string)$this->display_id,
  29. 'naming_rule' => new NamingRuleSimpleResource($this->namingRule),
  30. ];
  31. }
  32. }