/** * Update an existing comment. * * @param int $postId * @param int $id * * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * @throws \Symfony\Component\HttpKernel\Exception\ConflictHttpException * * @return \Illuminate\Http\JsonResponse */ public function update($postId, $id) { $input = Binput::map(['edit_body' => 'body']); if (CommentRepository::validate($input, array_keys($input))->fails()) { throw new BadRequestHttpException('Your comment was empty.'); } $comment = CommentRepository::find($id); $this->checkComment($comment); $version = Binput::get('version'); if (empty($version)) { throw new BadRequestHttpException('No version data was supplied.'); } if ($version != $comment->version && $version) { throw new ConflictHttpException('The comment was modified by someone else.'); } $version++; $comment->update(array_merge($input, ['version' => $version])); return Response::json(['success' => true, 'msg' => 'Comment updated successfully.', 'comment_text' => nl2br(e($comment->body)), 'comment_id' => $id, 'comment_ver' => $version]); }