ReplyTransformer.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/15
  6. * Time: 17:08
  7. */
  8. namespace App\Transformers\Circle;
  9. use App\Models\InterestCircleMessageComment;
  10. use App\Models\PostComment;
  11. use App\Traits\PostTrait;
  12. use App\Traits\UserTrait;
  13. use Carbon\Carbon;
  14. use League\Fractal\TransformerAbstract;
  15. class ReplyTransformer extends TransformerAbstract
  16. {
  17. use UserTrait;
  18. public function transform(InterestCircleMessageComment $postComment)
  19. {
  20. $user = $this->userInfo($postComment['uid']);
  21. $replyUsername = '';
  22. if($postComment['reply_uid']){
  23. $userReply = $this->userInfo($postComment['reply_uid']);
  24. $replyUsername = $userReply['username'];
  25. }
  26. return [
  27. 'id' => $postComment['id'],
  28. 'uid' => $postComment['uid'],
  29. 'username' => $user['username'],
  30. 'reply_username' => $replyUsername,
  31. 'avatar' => $user['avatar'],
  32. 'content' => $postComment['is_delete']?'该回复已被删除':$postComment['content'],
  33. 'created_at' => Carbon::parse($postComment['created_at'])->diffForHumans(),
  34. 'is_delete' => $postComment['is_delete']
  35. ];
  36. }
  37. }