title: Eloquent conditional where filter
body: <p>If I have a variable that is optional, and I only want to have it search on it if it is defined, I know that I can do this, but is there a way to define the function elsewhere, so I don't need to rewrite the same anonymous function over and over again? Or are the any other good alternatives to going about solving this problem?</p>
  
  <pre><code>.......-&gt;where(function($query) use ($gender){
              if ($gender) {
                  $query-&gt;where('gender', '=', $gender);
              }
              })-&gt;get();
  </code></pre>