Skip to content

Commit

Permalink
Perform ordering after query manipulation to allow for unions to be a…
Browse files Browse the repository at this point in the history
…ffect by ordering (breaking change)
  • Loading branch information
DivineOmega committed Nov 12, 2021
1 parent 4d86dcc commit 947df45
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/DataTableResponder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand All @@ -161,12 +167,6 @@ private function buildQuery(Request $request)
}
}

$queryManipulator = $this->queryManipulator;

if ($queryManipulator) {
$queryManipulator($query);
}

return $query;
}

Expand Down

0 comments on commit 947df45

Please sign in to comment.