/** * POST /comments * @param PostsInterface $postsInterface * @param CommentsTransformer $commentsTransformer * @return mixed */ public function store(PostsInterface $postsInterface, CommentsTransformer $commentsTransformer) { validate(['post_id' => 'required|integer', 'content' => 'required']); $user = user(); $post = $postsInterface->findPostWithException(inputGet('post_id')); $parentId = inputGet('parent_id'); if ($parentId) { $parent = $this->commentsInterface->findCommentWithException($parentId); } else { $parent = null; } $comment = $this->commentsInterface->createComment($user, $post, inputGet('content'), $parent); return respondWithItem($comment, $commentsTransformer); }