ArticleMapResource.php 1.2 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\MdRender;
  6. class ArticleMapResource 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. "collect_id" => $this->collect_id,
  19. "article_id" => $this->article_id,
  20. "level" => $this->level,
  21. "title" => $this->title,
  22. "editor"=> UserApi::getById($this->editor_id),
  23. "children" => $this->children,
  24. "deleted_at" => $this->deleted_at,
  25. "created_at" => $this->created_at,
  26. "updated_at" => $this->updated_at,
  27. ];
  28. $channels = [];
  29. if($request->has('channel')){
  30. $channels = explode('_',$request->get('channel')) ;
  31. }
  32. $mdRender = new MdRender(['format'=>'simple']);
  33. $data['title_text'] = $mdRender->convert($this->title,$channels);
  34. return $data;
  35. }
  36. }