SentHistoryResource.php 1.2 KB

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