/** * @api {get} /comments/:commentId/replies Get Comment Replies * @apiGroup Post Comments * @apiDescription Get replies to a comment. * * @param Comment $comment * * @return \Illuminate\Http\Response */ public function index(Comment $comment) { $comments = $comment->replies()->orderBy('likeCount', 'DESC')->orderBy('createdAt', 'ASC'); $paginator = $comments->paginate($this->getResultsPerPage()); $array = $this->paginatorToArray($paginator, 'comments'); // FIXME: Did I make this unnecessary already? // Load the replies to top-level comments foreach ($array['comments'] as &$comment) { /** @var Comment $comment */ $comment->load('replies'); } return $this->response($array); }
/** * Returns the next 3 levels of replies to a comment. * * @param Comment $comment * * @return Comment[] */ public function getCommentRepliesWithReplies(Comment $comment) { $comments = $comment->replies()->where('depth', '<=', $comment->depth + 3)->orderBy('depth', 'ASC')->orderBy('likeCount', 'DESC')->orderBy('createdAt', 'ASC')->get()->getDictionary(); //Get a dictionary keyed by primary keys return $this->sortCommentReplies($comments); }