Bladeren bron

feed昵称、头像

wzq 5 jaren geleden
bovenliggende
commit
9a5549ac33
2 gewijzigde bestanden met toevoegingen van 9 en 5 verwijderingen
  1. 6 3
      app/Repositories/FeedRepositories.php
  2. 3 2
      app/Transformers/FeedTransformer.php

+ 6 - 3
app/Repositories/FeedRepositories.php

@@ -204,13 +204,14 @@ class FeedRepositories
         if ($followStatus) {
             $isFollow = $followStatus;
         }
+        $user = $this->userInfo($post['uid']);
         return [
             'id' => $post['id'],
             'type' => $post['type'],
             'created_at' => Carbon::parse($post['created_at'])->diffForHumans(),
             'uid' => $post['uid'],
-            'username' => $post['username'],
-            'avatar' => $post['avatar'],
+            'username' => $user['username'],
+            'avatar' => $user['avatar'],
             'topic' => $topic,
             'title' => $post['title'],
             'content' => $post['content'],
@@ -235,12 +236,14 @@ class FeedRepositories
 
     public function getPostComment($post_id)
     {
-        $comments = $this->postComment->where(['post_id' => $post_id, 'parent_id' => 0])->select('id', 'uid', 'username', 'content', 'is_delete')->orderBy('is_delete', 'asc')->orderBy('id', 'desc')->take(2)->get();
+        $comments = $this->postComment->where(['post_id' => $post_id, 'parent_id' => 0])->select('id', 'uid', 'content', 'is_delete')->orderBy('is_delete', 'asc')->orderBy('id', 'desc')->take(2)->get();
         foreach ($comments as &$comment) {
             if ($comment->is_delete) {
                 $comment->content = '该评论已被删除';
             }
             unset($comment->is_delete);
+            $user = $this->userInfo($comment->uid);
+            $comment->username = $user['username'];
         }
         return $comments;
     }

+ 3 - 2
app/Transformers/FeedTransformer.php

@@ -32,12 +32,13 @@ class FeedTransformer extends TransformerAbstract {
                 unset($content->comment_id);
             }
         }
+        $user = $this->userInfo($feed['follow_uid']);
         return [
             'id' => $feed['id'],
             'uid' => $feed['uid'],
             'follow_uid' => $feed['follow_uid'],
-            'follow_username' => $feed['follow_username'],
-            'follow_avatar' => $feed['follow_avatar'],
+            'follow_username' => $user['username'],
+            'follow_avatar' => $user['avatar'],
            // 'follow_status' => $this->getFollowStatus($feed['uid'],$feed['follow_uid']),
             'type' => $feed['type'],
             'relate_id' => $feed['relate_id'],