title: Doctrine where if empty
body: <pre><code> $repository = $this-&gt;getEntityManager()-&gt;getRepository('App\Entity\HolidayPackages');
  
  $holiday_packages = $repository
              -&gt;createQueryBuilder('hp')
              -&gt;addSelect('hpt')
              -&gt;innerJoin('hp.holiday_packages_translation', 'hpt')
              -&gt;where('hpt.code = :code')
              -&gt;setParameter('code', $language_code)
              -&gt;andWhere('hpt.title LIKE :title')
              -&gt;setParameter('title', $title . '%');
  
          if (!empty($starting_date)) {
              $repository
                  -&gt;andWhere('hp.starting_date = :starting_date')
                  -&gt;setParameter('starting_date', $starting_date);
          }
  
          $repository
              -&gt;setFirstResult($offset)
              -&gt;setMaxResults($limit)
              -&gt;getQuery()
              -&gt;getResult();
  </code></pre>
  
  <p>I am trying to filter search. How can i check if parameter is empty, don' t add to where query ?</p>
  
  <p>I followed this link : <a href="https://stackoverflow.com/questions/7389767/doctrine2-querybuilder-empty-parameters">doctrine2 - querybuilder, empty parameters</a></p>
  
  <p>But i doesn't works for me.</p>
  
  <p>When i try to like that, i got an error :</p>
  
  <blockquote>
    <p>Undefined method 'setFirstResult'. The method name must start with either findBy or findOneBy!</p>
  </blockquote>
  
  <p>Thanks in advice..</p>
  
  <p><strong>Update</strong></p>
  
  <p>if i add to command line <code>setFirstResult</code> error change :</p>
  
  <blockquote>
    <p>Undefined method 'getQuery'. The method name must start with either findBy or findOneBy!</p>
  </blockquote>
  
  <p>When i used to use pdo, i can like this using bind parameters. But i don't know how to do in Doctrine.</p>