Skip to content

Commit

Permalink
order children array of each comment by created\_date in Review model
Browse files Browse the repository at this point in the history
  • Loading branch information
Divyeshhhh committed May 10, 2024
1 parent 51a5c82 commit dc10e9b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/models/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,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;
Expand Down

0 comments on commit dc10e9b

Please sign in to comment.