ProjectResource.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. use App\Http\Api\UserApi;
  5. use App\Http\Api\StudioApi;
  6. use App\Http\Api\ProjectApi;
  7. class ProjectResource extends JsonResource
  8. {
  9. /**
  10. * Transform the resource into an array.
  11. *
  12. * @param \Illuminate\Http\Request $request
  13. * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
  14. */
  15. public function toArray($request)
  16. {
  17. $data = [
  18. 'id' => $this->uid,
  19. 'title' => $this->title,
  20. 'type' => $this->type,
  21. 'weight' => $this->weight,
  22. 'description' => $this->description,
  23. 'executors_id' => json_decode($this->executors_id),
  24. 'parent_id' => $this->parent_id,
  25. 'parent' => ProjectApi::getById($this->parent_id),
  26. 'path' => ProjectApi::getListByIds(json_decode($this->path)),
  27. 'description' => $this->description,
  28. "owner" => StudioApi::getById($this->owner_id),
  29. "editor" => UserApi::getByUuid($this->editor_id),
  30. 'created_at' => $this->created_at,
  31. 'updated_at' => $this->updated_at,
  32. ];
  33. return $data;
  34. }
  35. }