SentHistoryResource.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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\ChannelApi;
  6. class SentHistoryResource extends JsonResource
  7. {
  8. /**
  9. * Transform the resource into an array.
  10. *
  11. * @param \Illuminate\Http\Request $request
  12. * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
  13. */
  14. public function toArray($request)
  15. {
  16. $data = [
  17. 'id' => $this->id,
  18. 'sent_uid' => $this->sent_uid,
  19. "editor" => UserApi::getByUuId($this->user_uid),
  20. 'content' => $this->content,
  21. 'landmark' => $this->landmark,
  22. 'pr_from' => $this->pr_from,
  23. 'created_at' => $this->created_at
  24. ];
  25. if($this->fork_from){
  26. $fork_from = ChannelApi::getById($this->fork_from);
  27. if($fork_from){
  28. $data['fork_from'] = $fork_from;
  29. }
  30. }
  31. if($this->accepter_uid){
  32. $data['accepter'] = UserApi::getByUuId($this->accepter_uid);
  33. }
  34. return $data;
  35. }
  36. }