title: how to use Laravel 8 query builder like eloquent for searching
body: <p>I'm developing a simple CRM with Laravel 8 that needs to search in query string.</p>
  <p>My query string would be look like:</p>
  <pre><code>http://127.0.0.1:8000/admin/users/supervisor?q=john&amp;gender=m
  </code></pre>
  <p>Now the problem is how can I search in controller?</p>
  <p>I want to do like this:</p>
  <pre><code>public function index (Request $request)
  {
      $role = getRoleCode($request-&gt;role);
      $roles = Role::where('role', '=', $role);
  
      if ($request-&gt;q) {
          $roles-&gt;where('name', 'like', &quot;%$request-&gt;$q%&quot;);
      }
  
      if ($request-&gt;gender) {
          $roles-&gt;where('gender', '=', $request-&gt;gender);
      }
  
      $role-&gt;orderBy('id', 'desc')-&gt;paginate(20);
  
      return view('admin.users.index', [
          'roles' =&gt; $roles,
          'role_name' =&gt; config('settings.roles')[$role],
          'role_en_name' =&gt; $request-&gt;role,
          'q' =&gt; $request-&gt;q,
          'gender' =&gt; $request-&gt;gender
      ]);
  }
  </code></pre>
  <p>I wonder why its not working and what is the standard way to do this.</p>
  <p>I've tried:</p>
  <pre><code>Role::query();
  </code></pre>
  <p>but that didn't work either.</p>
  <p>I've also tried:</p>
  <pre><code>$roles = Role::where('role', '=', $role)
      -&gt;where('name', 'like', &quot;%$request-&gt;$q%&quot;)
      -&gt;where('gender', '=', $request-&gt;gender)
      -&gt;orderBy('id', 'desc')
      -&gt;paginate(20);
  </code></pre>
  <p>This codes works perfectly but we may not be sending the &quot;q&quot; or &quot;gender&quot; URL params.</p>
  <p>PS: Sorry for my bad English :)</p>