title: filter eloquent models in laravel
body: <p>I have different filters for every category in my blade. when l click on every filter, page URL changes and filter name and filter value shows in URL, like this:</p>
  
  <blockquote>
    <p>127.0.0.1:8000/categories/search/9?brand[1]=Samsung&amp;brand[2]=Sony&amp;system=android</p>
  </blockquote>
  
  <p>As you see,every filter can be string or array.
  How can I get every filter name in my controller and filter products based on filter name and filter value?
  I wrote this conditions ,but these conditions only work if filters that are string, and I don't know how can I write conditions for array filters. This is my controller:</p>
  
  <pre><code>&lt;?php
  namespace App\Http\Controllers;
  use App\Category;
  use App\Filter;
  use App\product;
  use App\ProductQa;
  use Illuminate\Http\Request;
  class CategoryController extends Controller
  {
      public function index(Request $request)
      {
          $q = product::query();
          if ($request-&gt;has('brand')) {
              $q-&gt;where('brand', '=', $request-&gt;get('brand'));
          }
          if ($request-&gt;has('system')) {
              $q-&gt;where('system', '=', $request-&gt;get('system'));
          }
          return $q;
  
      }
  }
  </code></pre>