CourseMemberResource.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. class CourseMemberResource extends JsonResource
  7. {
  8. /**
  9. * Transform the resource into an array.
  10. *
  11. * @param \Illuminate\Http\Request $request
  12. * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
  13. */
  14. public function toArray($request)
  15. {
  16. $data = [
  17. "id"=>$this->id,
  18. "user_id"=> $this->user_id,
  19. "course_id"=> $this->course_id,
  20. "role"=> $this->role ,
  21. "user"=> UserApi::getByUuid($this->user_id),
  22. "editor"=> UserApi::getByUuid($this->editor_uid),
  23. "status"=> $this->status,
  24. 'channel_id'=> $this->channel_id,
  25. "created_at"=> $this->created_at,
  26. "updated_at"=> $this->updated_at,
  27. ];
  28. if($this->channel_id){
  29. $channel = ChannelApi::getById($this->channel_id);
  30. if($channel){
  31. $data['channel'] = $channel;
  32. }
  33. }
  34. return $data;
  35. }
  36. }