title: Laravel Eloquent : with query parameters
body: <p>I've finally worked out how to put together a complex query to get related models. </p>
  
  <p>This is what my query currently looks like...</p>
  
  <pre><code>    $campaign = Campaign::find($campaign_id);
      $buyers = $campaign-&gt;buyers()-&gt;with('notes')-&gt;with(['emails' =&gt; function($q){
          $q-&gt;where('campaign_id', '13');
      }])-&gt;get();
  </code></pre>
  
  <p>The complex part is I'm trying to get entries from <code>emails</code> that have both a matching <code>buyer_id</code> &amp; <code>campaign_id</code>. This query achieves exactly what I'm after in a pretty efficient way...</p>
  
  <p>BUT... I can't work out how to pass in parameters to the <code>with</code> closure. At the moment I've hard coded the id <code>13</code> into the <code>where</code> query in the closure but I want it to be equal to <code>$campaign_id</code> passed in to the original function. </p>
  
  <p>How do I do this?</p>