From 61fa5729fd3d7ac65e392dc896fc464d8bfa0220 Mon Sep 17 00:00:00 2001 From: crynobone Date: Sat, 26 Jul 2014 22:36:48 +0800 Subject: [PATCH] `Orchestra\Support\Traits\QueryFilterTrait::setupBasicQueryFilter()` should allow filtering none `*_at` fields. Signed-off-by: crynobone --- docs/changes.md | 4 ++++ src/Support/Traits/QueryFilterTrait.php | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index 390cfe0..5001b60 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -5,6 +5,10 @@ title: Support Change Log ## Version 2.2 {#v2-2} +### v2.2.2 {#v2-2-2} + +* `Orchestra\Support\Traits\QueryFilterTrait::setupBasicQueryFilter()` should allow filtering none `*_at` fields. + ### v2.2.1 {#v2-2-1} * Fixes exception shouldn't be thrown when casting `Orchestra\Support\Collection` to CSV when no data is available. diff --git a/src/Support/Traits/QueryFilterTrait.php b/src/Support/Traits/QueryFilterTrait.php index a8f8e85..d0978b3 100644 --- a/src/Support/Traits/QueryFilterTrait.php +++ b/src/Support/Traits/QueryFilterTrait.php @@ -14,15 +14,17 @@ trait QueryFilterTrait */ protected function setupBasicQueryFilter($query, array $input = array()) { - $order = Arr::get($input, 'order', null); - $sort = Str::upper(array_get($input, 'sort', '')); + $order = Arr::get($input, 'order', ''); + $sort = Str::upper(Arr::get($input, 'sort', null)); ! in_array($sort, ['ASC', 'DESC']) && $sort = 'ASC'; if (in_array($order, ['created', 'updated', 'deleted'])) { - $query->orderBy("{$order}_at", $sort); + $order = "{$order}_at"; } + ! empty($order) && $query->orderBy($order, $sort); + return $query; }