wzq преди 5 години
родител
ревизия
bec5b1c046
променени са 2 файла, в които са добавени 5 реда и са изтрити 1 реда
  1. 4 0
      app/Repositories/PostRepositories.php
  2. 1 1
      app/Transformers/Post/CommentTransformer.php

+ 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'],
         ];