title: Pagination for search results laravel 5.3
body: <h2>Pagination search results</h2>
  
  <p>I have just started with Laravel and I am trying to make a search function with proper pagination. The function works for page one but on page two it doesn't. I think it's not giving the results to the next page but I can't seem to find an answer.</p>
  
  <hr>
  
  <p><em>this is my search function inside IndexController:</em></p>
  
  <pre><code>public function search()
  {
      $q = Input::get('search');
  
      # going to next page is not working yet
      $product = Product::where('naam', 'LIKE', '%' . $q . '%')
          -&gt;orWhere('beschrijving', 'LIKE', '%' . $q . '%')
          -&gt;paginate(6);
  
      return view('pages.index', compact('product'));
  }
  </code></pre>
  
  <p><em>this is my route:</em></p>
  
  <pre><code>Route::post('search{page?}', 'IndexController@search');
  </code></pre>
  
  <p><em>this is the URL of page two:</em></p>
  
  <pre><code>/search?page=2
  </code></pre>
  
  <p><em>this is how I show my pagination:</em></p>
  
  <pre><code>{{ $product-&gt;appends(Request::get('page'))-&gt;links()}}
  </code></pre>
  
  <p><em>the error:</em></p>
  
  <pre><code>MethodNotAllowedHttpException in RouteCollection.php line 218:
  </code></pre>
  
  <hr>
  
  <p>Get error on request.</p>
  
  <p>Route:</p>
  
  <pre><code>Route::get('search/{page?}', 'IndexController@search');
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>MethodNotAllowedHttpException in RouteCollection.php line 218:
  in RouteCollection.php line 218
  at RouteCollection-&gt;methodNotAllowed(array('GET', 'HEAD')) in RouteCollection.php line 205
  at RouteCollection-&gt;getRouteForMethods(object(Request), array('GET', 'HEAD')) in RouteCollection.php line 158
  at RouteCollection-&gt;match(object(Request)) in Router.php line 780
  at Router-&gt;findRoute(object(Request)) in Router.php line 610
  at Router-&gt;dispatchToRoute(object(Request)) in Router.php line 596
  at Router-&gt;dispatch(object(Request)) in Kernel.php line 267
  at Kernel-&gt;Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
  at CheckForMaintenanceMode-&gt;handle(object(Request), object(Closure)) in Pipeline.php line 137
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
  at Pipeline-&gt;then(object(Closure)) in Kernel.php line 149
  at Kernel-&gt;sendRequestThroughRouter(object(Request)) in Kernel.php line 116
  at Kernel-&gt;handle(object(Request)) in index.php line 53
  </code></pre>
  
  <hr>
  
  <p>I hope my question is clear and in the right format. Thank you in advance (sorry for my bad English)</p>
  
  <hr>
  
  <p><strong>Answer:</strong></p>
  
  <p>I ended up using the answer of this post in combination with some help of <a href="https://stackoverflow.com/questions/35212580/laravel-5-route-pagination-url-encoding-issue?rq=1">this</a> post</p>
  
  <p>I used a post function for the initial search and a get function for the following pages. This was possible because I'm now giving my search to the URL.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <ul>
  <li>added the initial error.</li>
  <li>added the <code>Route::get</code> error</li>
  <li>added answer</li>
  </ul>