ReplyTransformer.php 1.1 KB

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