LikeResource.php 882 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Http\Api\UserApi;
  4. use Illuminate\Contracts\Support\Arrayable;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Http\Resources\Json\JsonResource;
  7. class LikeResource extends JsonResource
  8. {
  9. /**
  10. * Transform the resource into an array.
  11. *
  12. * @param Request $request
  13. * @return array|Arrayable|\JsonSerializable
  14. */
  15. public function toArray($request)
  16. {
  17. $data = [
  18. 'id' => $this->id,
  19. 'type' => $this->type,
  20. 'target_id' => $this->target_id,
  21. 'target_type' => $this->target_type,
  22. 'context' => $this->context,
  23. 'updated_at' => $this->updated_at,
  24. 'created_at' => $this->created_at,
  25. ];
  26. if ($this->user_id) {
  27. $data['user'] = UserApi::getByUuid($this->user_id);
  28. }
  29. return $data;
  30. }
  31. }