diff --git a/src/models/Review.php b/src/models/Review.php index 91abf6c..fb74c64 100644 --- a/src/models/Review.php +++ b/src/models/Review.php @@ -270,6 +270,13 @@ public function getNestedComments(): array } } + // Order the children array of each comment by created_date + foreach ($commentMap as $comment) { + usort($comment->children, function($a, $b) { + return strtotime($a->created_date) - strtotime($b->created_date); + }); + } + // Filter out comments that have a parent (i.e., retain only root-level comments) $nestedComments = array_filter($commentMap, function ($review) { return $review->parent_comment_id === null;