title: How to pass parameter to whereHas() clause in Laravel
body: <p>I queried the Category model to get all the ids where <code>'name', '=', $name</code> to use to query the Post model but I get an error.</p>
  
  <pre class="lang-php prettyprint-override"><code>public function getList($name)
  {
      $category_id = Category::where('name', '=', $name)-&gt;first()-&gt;id;
  
      $posts = Post::whereHas('category', function ($q) use ($category_id) {
          $q-&gt;where('id', '=', $category_id);
      })-&gt;paginate(12);
  
      return view('blog.index')-&gt;withPosts($posts)-&gt;withName($name);
  }
  </code></pre>
  
  <p>Here's my error.</p>
  
  <blockquote>
    <p>ErrorException in Builder.php line 877: compact(): Undefined variable:
    operator</p>
  </blockquote>