Skip to content

Commit

Permalink
Fix ignoring zero filters
Browse files Browse the repository at this point in the history
  • Loading branch information
50bhan committed Sep 4, 2020
1 parent bffceba commit 91220dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/ServiceProvider.php
Expand Up @@ -76,15 +76,15 @@ private function registerMacros()
if (is_array($value)) {
$result = [];
array_walk_recursive($value, static function ($val) use (&$result) {
if (!empty($val)) {
if (isset($val) && strlen($val) !== 0) {
$result[] = $val;
}
});

return !empty($result);
}

return !is_int($filter) && !empty($value);
return !is_int($filter) && (isset($value) && strlen($value) !== 0);
});

return $filters->all();
Expand Down
14 changes: 12 additions & 2 deletions tests/CollectionMacrosTest.php
Expand Up @@ -11,6 +11,7 @@ public function it_can_remove_lacking_value()
'city' => 'isfahan',
'name',
'gender' => '',
'level' => 0,
'age' => null,
'date' => [
'from' => '',
Expand All @@ -21,7 +22,7 @@ public function it_can_remove_lacking_value()
'max' => '',
],
'area' => [
'min' => 50,
'min' => 0,
'max' => 100,
],
'rental' => [
Expand All @@ -30,17 +31,22 @@ public function it_can_remove_lacking_value()
'max' => 500,
],
],
'weight' => [
'min' => 0,
'max' => 0,
]
]);

$this->assertEquals(
[
'city' => 'isfahan',
'level' => 0,
'price' => [
'min' => 10000,
'max' => '',
],
'area' => [
'min' => 50,
'min' => 0,
'max' => 100,
],
'rental' => [
Expand All @@ -49,6 +55,10 @@ public function it_can_remove_lacking_value()
'max' => 500,
],
],
'weight' => [
'min' => 0,
'max' => 0,
]
],
$inputs->getFilters()
);
Expand Down

0 comments on commit 91220dc

Please sign in to comment.