123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/15
- * Time: 17:08
- */
- namespace App\Transformers\Post;
- use App\Models\PostComment;
- use App\Traits\PostTrait;
- use App\Traits\UserTrait;
- use Carbon\Carbon;
- use League\Fractal\TransformerAbstract;
- class ReplyTransformer extends TransformerAbstract
- {
- use UserTrait;
- use PostTrait;
- public function __construct($postId, $uid)
- {
- $this->postId = $postId;
- $this->uid = $uid;
- }
- public function transform(PostComment $postComment)
- {
- $user = $this->userInfo($postComment['uid']);
- $replyUsername = '';
- if($postComment['reply_uid']){
- $userReply = $this->userInfo($postComment['reply_uid']);
- $replyUsername = $userReply['username'];
- }
- $commentLike = $this->getCommentLike($this->postId, $postComment['id'], $this->uid);
- return [
- 'id' => $postComment['id'],
- 'uid' => $postComment['uid'],
- 'username' => $user['username'],
- 'reply_username' => $replyUsername,
- 'avatar' => $user['avatar'],
- 'content' => $postComment['is_delete']?'该回复已被删除':$postComment['content'],
- 'created_at' => Carbon::parse($postComment['created_at'])->diffForHumans(),
- 'is_delete' => $postComment['is_delete'],
- 'is_like' => $commentLike['is_like'],
- 'like_count' => $commentLike['like_count'],
- ];
- }
- }
|