Browse Source

回复数量

wzq 5 years ago
parent
commit
bec5b1c046

+ 4 - 0
app/Repositories/PostRepositories.php

@@ -300,6 +300,10 @@ class PostRepositories
         try{
             $comment = $this->postComment->create($data);
 
+            if($comment->parent_id){
+                $this->postComment->where('parent_id', $comment->parent_id)->increment('reply_count');
+            }
+
             DB::commit();
             if(!$comment->parent_id){
                 Redis::DEL('post_new_comment_'.$comment->post_id);

+ 1 - 1
app/Transformers/Post/CommentTransformer.php

@@ -53,7 +53,7 @@ class CommentTransformer extends TransformerAbstract
             'avatar' => $user['avatar'],
             'content' => $postComment['is_delete']?'该评论已被删除':$postComment['content'],
             'created_at' => Carbon::parse($postComment['created_at'])->diffForHumans(),
-            'reply_count' => PostComment::where('parent_id', $postComment['id'])->count(),
+            'reply_count' => $postComment['reply_count'],
             'reply' => $reply,
             'is_delete' => $postComment['is_delete'],
         ];