Skip to content

Commit

Permalink
Orchestra\Support\Traits\QueryFilterTrait::setupBasicQueryFilter()
Browse files Browse the repository at this point in the history
…should allow filtering none `*_at` fields.

Signed-off-by: crynobone <[email protected]>
  • Loading branch information
crynobone committed Jul 26, 2014
1 parent f26dd69 commit 61fa572
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions src/Support/Traits/QueryFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 61fa572

Please sign in to comment.