feat: 1:1 문의 댓글 API 개선

- 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 <noreply@anthropic.com>
This commit is contained in:
2025-12-29 09:23:38 +09:00
parent 3e74999e89
commit 63d8eb5a71
2 changed files with 13 additions and 3 deletions

View File

@@ -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();
}
}

View File

@@ -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');
}
/**