ChannelResource.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Http\Api\StudioApi;
  4. use Illuminate\Contracts\Support\Arrayable;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Http\Resources\Json\JsonResource;
  7. class ChannelResource 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. 'uid' => $this->uid,
  19. 'name' => $this->name,
  20. 'summary' => $this->summary,
  21. 'type' => $this->type,
  22. 'studio' => StudioApi::getById($this->owner_uid),
  23. 'lang' => $this->lang,
  24. 'is_system' => $this->is_system,
  25. 'status' => $this->status,
  26. 'created_at' => $this->created_at,
  27. 'updated_at' => $this->updated_at,
  28. 'source_type' => $this->source_type,
  29. 'source_id' => $this->source_id,
  30. ];
  31. if (isset($this->source_type)) {
  32. $data['source_type'] = $this->source_type;
  33. }
  34. if (isset($this->source_id)) {
  35. $data['source_id'] = $this->source_id;
  36. }
  37. if (isset($this->progress)) {
  38. $data['progress'] = $this->progress;
  39. }
  40. if (isset($this->role)) {
  41. $data['role'] = $this->role;
  42. }
  43. return $data;
  44. }
  45. }