public function deleteAction(Request $request): JsonResponse { try { $comentId = $request->get('id'); $this->em->createQuery('DELETE FROM App\Model\Comment c WHERE c.id = :id') ->setParameter('id', $comentId)->execute(); $post = $this->em->getRepository('App\Model\Post')->findOneById($request->get('postId')); $post->setCommentsNum($post->getCommentsNum() -1); $this->em->persist($post); $this->em->flush(); return AdminSuccessJson::createResponse(); } catch (\Throwable $t) { return AdminErrorJson::createResponse($t->getMessage()); } }
public function deleteAction(Request $request): JsonResponse { try { $postId = $request->get('id'); $post = $this->em->getRepository('App\Model\Post')->findOneById($postId); if ($post->getImage()) { $imageFile = $this->uploadDir.'/'.$post->getImage(); unlink($imageFile); } $this->em->remove($post); $this->em->flush(); return AdminSuccessJson::createResponse(); } catch (\Throwable $t) { return AdminErrorJson::createResponse($t->getMessage()); } }
public function deleteAction(Request $request): JsonResponse { try { $user = $this->getUser($request->get('id')); $this->em->remove($user); $this->em->flush(); return AdminSuccessJson::createResponse(); } catch (\Throwable $t) { return AdminErrorJson::createResponse($t->getMessage()); } }