title: How to fix "laravel pagination NOT updating on search"
body: <p>I'm making a table of orders that have a specific current step in this case the step is 'NESTEN' and some other where statements to get the orders back that I need. </p>
  
  <p>Because I don't want a list with more than 400 orders on 1 page I want to use laravels pagination functionality that also give a performance boost on the list of more than 100.000 records. The laravel pagination works as is should but the problem comes when I want to use the filter I made. </p>
  
  <p>I made a dropdown list that needs to filter based on material of the orders that are in the list. In the table I see the filtered orders but the pagination has the same page count and order count as before. So to the point, the problem is that the pagination is not updating after filtering the collection from the query.</p>
  
  <p>What I already tried was some googling and found several solutions that didn't solve my problem or even caused more problems...</p>
  
  <p>Also added a $orders->filter function to remove orders that don't meet up the filter requirements but no result...</p>
  
  <p>To keep it understandable for now I added the code in the Route file.</p>
  
  <p>My route is as followed</p>
  
  <pre><code>Route::get('orders/nesten', function(Request $request) {
      $orders = ShopOrder::where([
          ['ItemCode', 'LIKE', 'CM%'],
          ['Exact', '=', null],
          ['Nesting', '=', null],
          ['IsOnHold', '!=', 1],
          ['ShopOrderRoutingStepPlanCount', '!=', 0]
      ])-&gt;paginate(50);
  
      $filteredCollection = $orders-&gt;filter(function ($order) use($request) {
          if($request-&gt;exists('material')) {
              return $order-&gt;getCurrentStep() == 'Nesten' 
                     &amp;&amp; $order-&gt;getMaterial() == $request-&gt;get('material');
          }
          return $order-&gt;getCurrentStep() == 'Nesten';
      });
  
      $orders-&gt;setCollection($filteredCollection);
      return view('dashboard/actions/Nesten')-&gt;with('shopOrders', $orders);
  });
  </code></pre>
  
  <p>In the ShopOrder Model I declared the functions ->getMaterial() and ->getCurrentStep() as</p>
  
  <pre><code>    public function routingStepPlans() {
          return $this-&gt;hasMany('App\Models\Exact\ShopOrder\RoutingStepPlan', 'ShopOrder', 'ID');
      }
  
      public function materialPlans() {
          return $this-&gt;hasMany('App\Models\Exact\ShopOrder\MaterialPlan', 'ShopOrder', 'ID');
      }
  
      public function getCurrentStep() {
          $current = $this-&gt;routingStepPlans()-&gt;where('LineNumber', ($this-&gt;timeTransactions()-&gt;count() + 1))-&gt;first();
  
          if(isset($current-&gt;Description)) {
              return $current-&gt;Description;
          }
  
          return 'Afgerond';
      }
  
      public function getMaterial() {
          $material = $this-&gt;materialPlans()-&gt;where('ItemCode', 'LIKE', 'TAP%')-&gt;first();
  
          if(isset($material-&gt;Description)) {
              return $material-&gt;Description;
          }
          return '-';
      }
  </code></pre>
  
  <p>and as last the view</p>
  
  <pre><code>        &lt;table class="table table-striped table-bordered no-width"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Order nummer&lt;/th&gt;
                      &lt;th&gt;SKU&lt;/th&gt;
                      &lt;th&gt;Omschrijving&lt;/th&gt;
                      &lt;th&gt;Aantal&lt;/th&gt;
                      &lt;th&gt;Datum&lt;/th&gt;
                      &lt;th&gt;Deadline&lt;/th&gt;
                      &lt;th&gt;Materiaal&lt;/th&gt;
                      &lt;th&gt;DXF?&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  @foreach($shopOrders as $shopOrder)
                      &lt;tr&gt;
                          &lt;td&gt;{{ $shopOrder-&gt;ShopOrderNumber }}&lt;/td&gt;
                          &lt;td&gt;{{ $shopOrder-&gt;ItemCode }}&lt;/td&gt;
                          &lt;td&gt;{{ str_replace('Car Mats', '',$shopOrder-&gt;Description) }}&lt;/td&gt;
                          &lt;td&gt;{{ $shopOrder-&gt;PlannedQuantity }}&lt;/td&gt;
                          &lt;td&gt;{{ $shopOrder-&gt;PlannedStartDate }} &lt;/td&gt;
                          &lt;td&gt;{{ $shopOrder-&gt;PlannedDate }}&lt;/td&gt;
                          &lt;td&gt;{{ $shopOrder-&gt;getMaterial() }}&lt;/td&gt;
                          &lt;td&gt;{{ $shopOrder-&gt;hasDxf() }}&lt;/td&gt;
                      &lt;/tr&gt;
                  @endforeach
              &lt;/tbody&gt;
          &lt;/table&gt;
          {{ $shopOrders-&gt;total() }}
          {{ $shopOrders-&gt;appends(['material' =&gt; Request::get('material')])-&gt;render() }} 
  </code></pre>
  
  <p>I expect 1 page from pagination with orders/nesten?material=Saxony%20Zwart&amp;page=1 as url since that material has 9 orders.</p>
  
  <p>But currently it still has 151 pages, the same as just going to orders/nesten.</p>