diff --git a/src/DataTableResponder.php b/src/DataTableResponder.php index 0d1c9b4..4ae5cd8 100644 --- a/src/DataTableResponder.php +++ b/src/DataTableResponder.php @@ -141,11 +141,17 @@ public function setResponseMeta(array $meta = []) */ private function buildQuery(Request $request) { + $query = $this->model->query(); + + $queryManipulator = $this->queryManipulator; + + if ($queryManipulator) { + $queryManipulator($query); + } + $orderByField = $request->get('orderByField'); $orderByDirection = $request->get('orderByDirection'); - $query = $this->model->query(); - if ($orderByField && $orderByDirection) { if (!in_array(strtolower($orderByDirection), ['asc', 'desc'])) { throw new InvalidArgumentException('Order by direction must be either asc or desc.'); @@ -161,12 +167,6 @@ private function buildQuery(Request $request) } } - $queryManipulator = $this->queryManipulator; - - if ($queryManipulator) { - $queryManipulator($query); - } - return $query; }