ProjectResource.php 1.3 KB

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