TransferResource.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 TransferResource 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. 'origin_owner' => StudioApi::getById($this->origin_owner),
  22. 'res_type' => $this->res_type,
  23. 'res_id' => $this->res_id,
  24. 'transferor' => UserApi::getByUuid($this->transferor_id),
  25. 'new_owner' => StudioApi::getById($this->new_owner),
  26. 'status' => $this->status,
  27. 'updated_at' => $this->updated_at,
  28. 'created_at' => $this->created_at,
  29. ];
  30. if (! empty($this->editor_id)) {
  31. $data['editor'] = UserApi::getByUuid($this->editor_id);
  32. }
  33. switch ($this->res_type) {
  34. case 'channel':
  35. $data['channel'] = ChannelApi::getById($this->res_id);
  36. break;
  37. default:
  38. // code...
  39. break;
  40. }
  41. return $data;
  42. }
  43. }