title: Laravel - building filter for results set using $_GET and query parameters in the url?
body: <p>I have a Laravel project with a results set representing a number of articles. I am trying to filter the results set by author using an author dropdown on the right hand side.</p>
  <p>I am trying to submit the form upon change of an author in the list, and have the author's name show up in the URL as one of the search params, e.g. <a href="http://127.0.0.1:8000/articles/?author=Bob" rel="nofollow noreferrer">http://127.0.0.1:8000/articles/?author=Bob</a>, but I am unsure of how to do this in Laravel.</p>
  <p>I also have a second filter for types (below the first one), and it would be nice to have a chained url query when both of the filters are selected - for example:
  <a href="http://127.0.0.1:8000/articles/?author=Bob&amp;type=review" rel="nofollow noreferrer">http://127.0.0.1:8000/articles/?author=Bob&amp;type=review</a>.</p>
  <p>How can I send a GET parameter to the URL upon an on chance event and submit the form via a GET request?</p>
  <p>My code so far: index.blade.php - showing author dropdown</p>
  <pre><code>    &lt;div class=&quot;right-panel&quot;&gt;
          &lt;?php $_GET['author-checkbox'] = &quot;&quot;; ?&gt;
          &lt;form action=&quot;{{ route('articles.filter', $_GET['author-checkbox']) }}&quot;, method=&quot;get&quot;&gt;
              @csrf
              &lt;label for=&quot;author-checkbox&quot; class=&quot;author selectbox&quot;&gt;Filter titles by Author: &amp;nbsp;&lt;/label&gt;
              &lt;select name=&quot;author-checkbox&quot; onchange=&quot;this.form.submit()&quot; id=&quot;author selectbox&quot; class=&quot;author selectbox&quot;&gt;
              
                  @if(!empty($articles) &amp;&amp; count($articles) &gt; 0)
                      &lt;option value=&quot;&quot;&gt;--Please select an author--&lt;/option&gt;   
                      @foreach($articles['data'] as $article)
                          @if(isset($article['authors'][0]))                        
                              @foreach($article['authors'] as $author)
                                  &lt;option value=&quot;{{ $author['id'] }}&quot;&gt;{{ $author['name'] }}&lt;/option&gt;
                              @endforeach
                          @endif
                      @endforeach
                  @endif
              &lt;/select&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  </code></pre>
  <p>// web.php - routes:</p>
  <pre><code>
      Route::get('/articles/filter/?author={author}', ['as' =&gt; 'articles.filter', 'uses' =&gt; 'ArticleController@filter']);
  
  </code></pre>
  <p>// ArticleController.php</p>
  <pre><code>public function filter(){
  if(isset($_GET('author-checkbox'))){ // filter titles by author
              $articlesJson = file_get_contents('https://content-store.explore.bfi.digital/api/articles');
  
              $typesJson = file_get_contents('https://content-store.explore.bfi.digital/api/types'); // Get list of available types.
  
              $objs = json_decode($articlesJson, true);
  
              $types = json_decode($typesJson, true);
  
              $filteredArticles = array();
              
              foreach($objs['data'] as $article){
                  if(isset($article['authors'][0])){
                      if($article['authors'][0]['id'] == $_GET('author-checkbox')){
                          $filteredArticles[] = $article;
                      }
                  }
              }
  
              $fullArticles = $objs;
  
              return view('articles.index')-&gt;with(['authorId' =&gt; $_GET('author-checkbox'), 'filteredArticles' =&gt; $filteredArticles, 'types' =&gt; $types, 'fullArticles' =&gt; $fullArticles]);
  
          } else if(isset($request-&gt;{'category-checkbox'})){
  
              $typeName = strtolower($request-&gt;{'category-checkbox'});
              
              $articlesJson = file_get_contents('https://content-store.explore.bfi.digital/api/articles?type=' . $typeName);
  
              $typesJson = file_get_contents('https://content-store.explore.bfi.digital/api/types'); // Get list of available types.
  
              $types = json_decode($typesJson, true);
  
              $objs = json_decode($articlesJson, true);
  
              $filteredArticles = array();
              foreach($objs['data'] as $article){
                  if(isset($article['type']['name'])){
                      if($article['type']['name'] == $request-&gt;{'category-checkbox'}){
                          $filteredArticles[] = $article;
                      }
                  }
              }
              
              $fullArticles = $objs;
  
              return view('articles.index')-&gt;with(['typeName' =&gt; $request-&gt;{'category-checkbox'}, 'authorId' =&gt; &quot;&quot;, 'filteredArticles' =&gt; $filteredArticles, 'fullArticles' =&gt; $fullArticles, 'types' =&gt; $types]);
          }
  
  If anyone has any idea, that would be great.
  Thanks,
  Rob
  </code></pre>