TermResource.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. use App\Http\Api\ChannelApi;
  5. use App\Http\Api\StudioApi;
  6. use App\Http\Api\UserApi;
  7. class TermResource 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. "guid"=>$this->guid,
  20. "word"=> $this->word,
  21. "word_en"=> $this->word_en,
  22. "meaning"=> $this->meaning,
  23. "other_meaning"=> $this->other_meaning,
  24. "tag"=> $this->tag,
  25. "note"=> $this->note,
  26. "language"=> $this->language,
  27. "channal"=> $this->channal,
  28. "studio" => StudioApi::getById($this->owner),
  29. "editor"=> UserApi::getById($this->editor_id),
  30. "created_at"=> $this->created_at,
  31. "updated_at"=> $this->updated_at,
  32. ];
  33. if(!empty($this->channal)){
  34. $data["channel"] = ChannelApi::getById($this->channal);
  35. }
  36. return $data;
  37. }
  38. }