SentPrResource.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. use App\Http\Api\MdRender;
  5. use App\Http\Api\StudioApi;
  6. use App\Http\Api\AuthApi;
  7. use App\Http\Api\ChannelApi;
  8. class SentPrResource extends JsonResource
  9. {
  10. /**
  11. * Transform the resource into an array.
  12. *
  13. * @param \Illuminate\Http\Request $request
  14. * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
  15. */
  16. public function toArray($request)
  17. {
  18. //获取用户信息
  19. $user = AuthApi::current($request);
  20. $role = 'reader';
  21. if($user && $user["user_uid"] === $this->editor_uid ){
  22. $role = 'owner';
  23. }
  24. $channel = ChannelApi::getById($this->channel_uid);
  25. $mode = $request->get("mode",'read');
  26. return [
  27. "id"=>$this->id,
  28. "book"=> $this->book_id,
  29. "paragraph"=> $this->paragraph,
  30. "word_start"=> $this->word_start,
  31. "word_end"=> $this->word_end,
  32. "editor"=> StudioApi::getById($this->editor_uid),
  33. "channel"=> $channel,
  34. "content"=>$this->content,
  35. "html"=> MdRender::render($this->content,$this->channel_uid,null,$mode,$channel['type']),
  36. "role"=>$role,
  37. "created_at"=> $this->created_at,
  38. "updated_at"=> $this->updated_at,
  39. ];
  40. }
  41. }