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