title: Eloquent grouped orWhere
body: <p>Currently have an Eloquent statement:</p>
  
  <pre><code>$contacts = Contacts::where('lname','LIKE',$searchquery.'%')
      -&gt;orWhere('fname','LIKE',$searchquery.'%')
      -&gt;orWhere('phone','LIKE','%'.$searchquery)
      -&gt;where('active','=',1)-&gt;get();
  </code></pre>
  
  <p>It is treating it as</p>
  
  <pre><code>select 
      * 
  from 
      contacts 
  where 
      lname like $searchquery+'%' 
      or lname like $searchquery+'%' 
      or lname like $searchquery+'%' 
      and active = 1
  </code></pre>
  
  <p>what I am needing is</p>
  
  <pre><code>select 
      * 
  from 
      contacts 
  where 
      (lname like $searchquery+'%' 
      or lname like $searchquery+'%' 
      or lname like $searchquery+'%') 
      and active = 1
  </code></pre>
  
  <p>How do I go about grouping in Eloquent?  I have found a couple examples such as:</p>
  
  <pre><code>DB::table('users')
          -&gt;where('name', '=', 'John')
          -&gt;orWhere(function ($query) {
              $query-&gt;where('votes', '&gt;', 100)
                    -&gt;where('title', '&lt;&gt;', 'Admin');
          })
          -&gt;get();
  </code></pre>
  
  <p>But I am only used to Eloquent, not Laravels DB Query builder.  I tried adapting the Eloquent form to this</p>
  
  <pre><code>$contacts = Contacts::-&gt;where('active', '=', '1')
          -&gt;where(function ($query) {
              $query-&gt;orWhere('lname', 'LIKE', $searchquery.'%')
                    -&gt;orWhere('lname', 'LIKE', $searchquery.'%')
                    -&gt;orWhere('phone', 'LIKE', '%'.$searchquery);
          })
          -&gt;get();
  </code></pre>
  
  <p>No success as it does not recognize the <code>$searchquery</code> inside the function.</p>
  
  <p>What am I missing?</p>