SentHistoryResource.php 1.2 KB

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