title: How to show Laravel model with belongsToMany connection if has specified connection?
body: <p>I have this product model:</p>
  
  <pre><code>public function categories() {
      return $this-&gt;belongsToMany('App\Category', 'product_categories');
  }
  </code></pre>
  
  <p>And in my controller:</p>
  
  <pre><code>public function search(Request $request) {
      return Product::with([
          'categories' =&gt; function($categories) use ($request) {
              // ...
          }
      ]);
  }
  </code></pre>
  
  <p>If I try to use <code>$request</code> in the <code>categories</code> function it's search only in categories, but shows all products.</p>
  
  <p>How do I show <strong>only</strong> that products whitch has defined categories in <code>$request-&gt;category_id</code>?</p>