title: Laravel Sort Results by Query and URL
body: <p>I want sort my Search Results with an URL. I cant use Controller in my way because i use Route for <code>/search</code>.</p>
  
  <p>My Search Route:</p>
  
  <pre><code>Route::get ( '/', function () {
      $mydb= Product::paginate(200);
      return view ( 'search' )-&gt;withProduct($mydb);
  } );
  
      Route::any ( '/search', function () {
          $q = Input::get ( 'q' );
  
          $sort = Product::where ( 'name', 'LIKE', '%' . $q . '%' )-&gt;orderBy('created_at','desc')-&gt;paginate(20);
  
  
          if($q != ""){
          $products = Product::where ( 'name', 'LIKE', '%' . $q . '%' )-&gt;orWhere ( 'description', 'LIKE', '%' . $q . '%' )-&gt;paginate (200)-&gt;setPath ( '' );
          $pagination = $products-&gt;appends ( array (
                      'q' =&gt; Input::get ( 'q' ) 
              ) );
  
  
  
  
          if (count ( $products ) &gt; 0)
              return view ( 'search' )-&gt;withDetails ( $products )-&gt;withQuery ( $q );
          }
  </code></pre>
  
  <p>Now i want create an Button where i can Sort the results from <code>query</code> search.</p>
  
  <p>Button Example:</p>
  
  <pre><code>&lt;a href="/search?q={{ $query }}"&gt;Sort by Price&lt;/a&gt;
  </code></pre>
  
  <p>I want add like this to my Route:</p>
  
  <pre><code>$sort = Product::where ( 'name', 'LIKE', '%' . $q . '%' )-&gt;orderBy('created_at','desc')-&gt;paginate(20);
  </code></pre>
  
  <p>This dont work..
  And then add the <code>{{ $sort }}</code>behind my Button URL like:</p>
  
  <pre><code>&lt;a href="/search?q={{ $query }}&amp;`{{ $sort }}"&gt;Sort by Price&lt;/a&gt;
  </code></pre>
  
  <p>Any Idea how i can do it correct? Sorry i am an Beginner with Laravel and i know its not correct.</p>
  
  <p>Thanks!</p>