TransferResource.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. use App\Http\Api\StudioApi;
  5. use App\Http\Api\UserApi;
  6. use App\Http\Api\ChannelApi;
  7. class TransferResource 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. "origin_owner"=>StudioApi::getById($this->origin_owner),
  20. "res_type"=>$this->res_type,
  21. "res_id"=> $this->res_id,
  22. "transferor"=> UserApi::getByUuid($this->transferor_id),
  23. "new_owner"=> StudioApi::getById($this->new_owner),
  24. "status"=> $this->status,
  25. "updated_at"=> $this->updated_at,
  26. "created_at"=> $this->created_at,
  27. ];
  28. if(!empty($this->editor_id)){
  29. $data['editor'] = UserApi::getByUuid($this->editor_id);
  30. }
  31. switch ($this->res_type) {
  32. case 'channel':
  33. $data['channel'] = ChannelApi::getById($this->res_id);
  34. break;
  35. default:
  36. # code...
  37. break;
  38. }
  39. return $data;
  40. }
  41. }