Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Commit

Permalink
Removed default ordering form query
Browse files Browse the repository at this point in the history
  • Loading branch information
hcaz authored Jun 27, 2022
1 parent 2a26198 commit fde62c8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/FromRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,15 @@ function (Builder $sub_query) use ($request, $namespace, $key) {
}

// Ordering
$column = $request->input("$namespace.order.column", "id");
$order = $request->input("$namespace.order.direction", "asc");
if ($this->isValidField($column) && in_array($order, ["asc", "desc"])) {
$query = $query->orderBy($column, $order);
}
if ($order == "rnd") {
$query = $query->inRandomOrder();
if($request->filled("$namespace.order")) {
$column = $request->input("$namespace.order.column", "id");
$order = $request->input("$namespace.order.direction", "asc");
if ($this->isValidField($column) && in_array($order, ["asc", "desc"])) {
$query = $query->orderBy($column, $order);
}
if ($order == "rnd") {
$query = $query->inRandomOrder();
}
}

return $query;
Expand Down

0 comments on commit fde62c8

Please sign in to comment.