From 63d8eb5a717b28c7f1308afe165100ba4cb6eefe Mon Sep 17 00:00:00 2001 From: kent Date: Mon, 29 Dec 2025 09:23:38 +0900 Subject: [PATCH] =?UTF-8?q?feat:=201:1=20=EB=AC=B8=EC=9D=98=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20API=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - BoardComment 모델에 replies() 관계 추가 (children 별칭) - PostService 댓글 CRUD에 user eager loading 추가 - getComments(): with(['user', 'replies.user']) - createComment(): $comment->load('user') - updateComment(): $comment->fresh('user') - 댓글 작성자 이름 정상 표시 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- app/Models/Boards/BoardComment.php | 8 ++++++++ app/Services/Boards/PostService.php | 8 +++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Models/Boards/BoardComment.php b/app/Models/Boards/BoardComment.php index 6aa5321..43b965c 100644 --- a/app/Models/Boards/BoardComment.php +++ b/app/Models/Boards/BoardComment.php @@ -38,4 +38,12 @@ public function children() { return $this->hasMany(BoardComment::class, 'parent_id')->where('status', 'active'); } + + /** + * Alias for children() - used by PostService eager loading + */ + public function replies() + { + return $this->children(); + } } diff --git a/app/Services/Boards/PostService.php b/app/Services/Boards/PostService.php index 3e61dd9..e6985fb 100644 --- a/app/Services/Boards/PostService.php +++ b/app/Services/Boards/PostService.php @@ -569,7 +569,7 @@ public function getComments(int $postId): Collection return BoardComment::where('post_id', $postId) ->whereNull('parent_id') ->where('status', 'active') - ->with('replies') + ->with(['user', 'replies.user']) ->orderBy('created_at') ->get(); } @@ -585,7 +585,9 @@ public function createComment(int $postId, array $data): BoardComment $data['ip_address'] = request()->ip(); $data['status'] = 'active'; - return BoardComment::create($data); + $comment = BoardComment::create($data); + + return $comment->load('user'); } /** @@ -602,7 +604,7 @@ public function updateComment(int $commentId, array $data): ?BoardComment $comment->update($data); - return $comment->fresh(); + return $comment->fresh('user'); } /**