title: Symfony - delete by ID
body: <p>I defined mu delete function to delete row by ID but everytime i try something new I get an error so I doubt that my logic is right.</p>
  
  <p>this is my controller and service</p>
  
  <pre><code>public function deleteUser($id)
  {
      $query = $this-&gt;getUserRepository()
          -&gt;createQueryBuilder('du')
          -&gt;delete('du')
          -&gt;where('du.id = :id')
          -&gt;setParameter("id", $id)
          -&gt;getQuery()
          -&gt;execute();
  
      return $query;
  }
  
  /**
   * @param $id
   * @Route("/users/delete/{id}", name="user_delete")
   * @return \Symfony\Component\HttpFoundation\JsonResponse
   * @throws \Doctrine\Common\Annotations\AnnotationException
   */
  public function getUserDeleteAction($id)
  {
  
      $this-&gt;get('user')-&gt;deleteUser($id);
  
      return $this-&gt;success();
  }
  </code></pre>