You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
755 B

  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. class TaskResource extends JsonResource
  5. {
  6. /**
  7. * Transform the resource into an array.
  8. *
  9. * @param \Illuminate\Http\Request $request
  10. * @return array
  11. */
  12. public function toArray($request)
  13. {
  14. foreach ($this->getAttributes() as $attribute => $value) {
  15. $resource[$attribute] = $value;
  16. if ($attribute == 'watchers') {
  17. $resource[$attribute] = json_decode($value);
  18. }
  19. }
  20. $resource['tags'] = $this->tagTask()->pluck('tag_id')->toArray();
  21. $resource['works'] = $this->works;
  22. $resource['comments'] = $this->comments;
  23. return $resource;
  24. }
  25. }