SentPrResource.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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\ChannelApi;
  7. class SentPrResource 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. //判断权限
  18. $user = AuthApi::current($request);
  19. $role = 'reader';
  20. if($user && $user["user_uid"] === $this->editor_uid ){
  21. $role = 'owner';
  22. }
  23. return [
  24. "id"=>$this->id,
  25. "book"=> $this->book_id,
  26. "paragraph"=> $this->paragraph,
  27. "word_start"=> $this->word_start,
  28. "word_end"=> $this->word_end,
  29. "editor"=> StudioApi::getById($this->editor_uid),
  30. "channel"=> ChannelApi::getById($this->channel_uid),
  31. "content"=>$this->content,
  32. "html"=> MdRender::render($this->content,$this->channel_uid),
  33. "role"=>$role,
  34. "created_at"=> $this->created_at,
  35. "updated_at"=> $this->updated_at,
  36. ];
  37. }
  38. }