commentRepo->getQueryForVisible(); return $this->apiListingResponse($query, [ 'id', 'commentable_id', 'commentable_type', 'parent_id', 'local_id', 'content_ref', 'created_by', 'updated_by', 'created_at', 'updated_at' ]); } /** * Read the details of a single comment, along with its direct replies. */ public function read(string $id): JsonResponse { $comment = $this->commentRepo->getQueryForVisible() ->where('id', '=', $id)->firstOrFail(); $replies = $this->commentRepo->getQueryForVisible() ->where('parent_id', '=', $comment->local_id) ->where('commentable_id', '=', $comment->commentable_id) ->where('commentable_type', '=', $comment->commentable_type) ->get(); /** @var Comment[] $toProcess */ $toProcess = [$comment, ...$replies]; foreach ($toProcess as $commentToProcess) { $commentToProcess->setAttribute('html', $commentToProcess->safeHtml()); $commentToProcess->makeVisible('html'); } $comment->setRelation('replies', $replies); return response()->json($comment); } }