fix: 🐛 add a default behavior in sortQuery method in Controller.php to have the query orderByDesc if no query string
This commit is contained in:
parent
09d84e31fb
commit
4c8f5f20f7
1 changed files with 10 additions and 7 deletions
|
|
@ -216,13 +216,16 @@ class Controller extends BaseController
|
|||
Session::remove("$rName.sort_col");
|
||||
Session::remove("$rName.sort_way");
|
||||
}
|
||||
if (request()->sort_col and request()->sort_way and Schema::hasColumn($table, request()->sort_col)) {
|
||||
if (
|
||||
!isset($ignore) or
|
||||
(isset($ignore) and !in_array(request()->sort_col, $ignore))
|
||||
) {
|
||||
$query = $query->orderBy(\sprintf("$table.%s", request()->sort_col), request()->sort_way);
|
||||
}
|
||||
if (
|
||||
request()->sort_col &&
|
||||
request()->sort_way &&
|
||||
Schema::hasColumn($table, request()->sort_col) &&
|
||||
(!isset($ignore) || (isset($ignore) && !in_array(request()->sort_col, $ignore)))
|
||||
) {
|
||||
$query = $query->orderBy("$table." . request()->sort_col, request()->sort_way);
|
||||
} else {
|
||||
// Else, orderByDesc by default.
|
||||
$query = $query->orderByDesc("$table.created_at");
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue