title: Eloquent datatables not applying where(), orderBy(), etc
body: <p>I've written a class which takes an Eloquent Model and manipulates it in order to output JSON for a <a href="https://datatables.net/" rel="nofollow noreferrer">datatable</a>. The datatable uses server side processing via a POST request.</p>
  
  <p>Here is the class:</p>
  
  <pre><code>namespace App\Helpers;
  
  class Datatable {
      public static $request;
      public static $model;
      public static $records_total;
      public static $records_filtered;
  
      static function make ($request, $model) {
          self::$request = $request;
          self::$model = $model;
          self::setRecordsTotal();
          self::filter();
          self::setRecordsFiltered();
          self::orderLimit();
          self::renderJson();
      }
  
      // set total record count
      static function setRecordsTotal () {
          self::$records_total = self::$model-&gt;count();
      }
  
      // filter by search query
      static function filter () {
          if (!empty(self::$request['search']['value'])) {
              foreach (self::$request['columns'] as $column) {
                  if ($column['searchable'] == 'true') {
                      self::$model-&gt;where($column['data'], 'LIKE', '%'.self::$request['search']['value'].'%');
                  }
              }
          }
      }
  
      // set filtered record count
      static function setRecordsFiltered () {
          self::$records_filtered = self::$model-&gt;count();
      }
  
      // apply order by &amp; limit
      static function orderLimit () {
          self::$model-&gt;orderBy(self::$request['columns'][self::$request['order'][0]['column']], self::$request['order'][0]['dir']);
          self::$model-&gt;skip(self::$request['start'])-&gt;take(self::$request['length']);
      }
  
      // render json output
      static function renderJson () {
          $array = [];
          $array['draw'] = self::$request['draw'];
          $array['recordsTotal'] = self::$records_total;
          $array['recordsFiltered'] = self::$records_filtered;
          $array['data'] = [];
          $results = self::$model-&gt;get();
  
          foreach ($results as $result) {
              $array['data'][] = $result-&gt;toArray();
          }
  
          echo json_encode($array);
      }
  }
  </code></pre>
  
  <p>Here is how I call the class:</p>
  
  <pre><code>Datatable::make($_POST, new User());
  </code></pre>
  
  <p>So <code>User</code> is an Eloquent model in this instance.</p>
  
  <p>Now, the initial rendering of the datatable works great. However, when I try and search or order it, it seems like my code within the <code>filter()</code> and <code>orderLimit()</code> methods is not being applied, because it just keeps spitting out the exact same results in the exact same order.</p>
  
  <p>Why are my <code>where()</code>, <code>orderBy()</code>, etc. not being applied to the Model properly?</p>