ArticleResource.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. use App\Http\Api\MdRender;
  5. class ArticleResource extends JsonResource
  6. {
  7. /**
  8. * Transform the resource into an array.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
  12. */
  13. public function toArray($request)
  14. {
  15. $data = [
  16. "uid" => $this->uid,
  17. "title" => $this->title,
  18. "subtitle" => $this->subtitle,
  19. "summary" => $this->summary,
  20. "studio"=> \App\Http\Api\StudioApi::getById($this->owner),
  21. "editor"=> \App\Http\Api\UserApi::getById($this->editor_id),
  22. "status" => $this->status,
  23. "lang" => $this->lang,
  24. "created_at" => $this->created_at,
  25. "updated_at" => $this->updated_at,
  26. ];
  27. if(isset($this->content) && !empty($this->content)){
  28. $data["content"] = $this->content;
  29. $data["content_type"] = $this->content_type;
  30. $data["html"] = MdRender::render($this->content,$request->get('channel'));
  31. }
  32. return $data;
  33. }
  34. }