Skip to content

Commit

Permalink
Possibility to ignore string parameter when it's empty
Browse files Browse the repository at this point in the history
  • Loading branch information
mnabialek committed Jun 15, 2016
1 parent 4c66cca commit 074b27e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Parsers/SimpleQueryParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class SimpleQueryParser implements InputParser
*/
protected $sortDescSign = '-';

/**
* Ignore filters with empty values
*
* @var bool
*/
protected $ignoreEmptyFilters = false;

/**
* @var Collection
*/
Expand Down Expand Up @@ -65,7 +72,15 @@ public function getFilters()

$filters = $this->collection->make();

$input->each(function ($value, $field) use ($filters) {
$input->filter(function ($value) {
if ($this->ignoreEmptyFilters && is_string($value) &&
(string)$value == ''
) {
return false;
}

return true;
})->each(function ($value, $field) use ($filters) {
$filter = new Filter();
$filter->setField($field);
$filter->setValue($value);
Expand Down

0 comments on commit 074b27e

Please sign in to comment.