LikeResource.php 852 B

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