Permalink
Browse files

Also check if a value is null because of the ConvertEmptyStringsToNul…

…l middleware introduced in Laravel 5.4
  • Loading branch information...
cerbero90 committed Aug 16, 2017
1 parent d275738 commit 6621e3fbb4fb46d24cc8bbf63da0798d47d8b347
Showing with 14 additions and 1 deletion.
  1. +2 −1 src/QueryFilters.php
  2. +11 −0 tests/TestFilters.php
  3. +1 −0 tests/spec/TestFiltersSpec.php
View
@@ -88,7 +88,8 @@ public function applyToQuery(Builder $query)
protected function filterCanBeApplied($filter, $value)
{
$filterExists = method_exists($this, $filter);
$valueIsLegit = $value !== '' || in_array($filter, $this->implicitFilters);
$hasValue = $value !== '' && $value !== null;
$valueIsLegit = $hasValue || in_array($filter, $this->implicitFilters);
return $filterExists && $valueIsLegit;
}
View
@@ -73,6 +73,17 @@ public function fooBarBaz($value)
$this->filters['foo-bar_baz'] = $value;
}
/**
* Dummy filter never called.
*
* @author Andrea Marco Sartori
* @return void
*/
public function test()
{
$this->filters['test'] = null;
}
/**
* Dummy filter requiring no values.
*
@@ -39,6 +39,7 @@ public function it_applies_explicit_filters($request, Builder $query)
'bar' => '0',
'baz' => '',
'foo-bar_baz' => 'null',
'test' => null,
];
$appliedFilters = [

0 comments on commit 6621e3f

Please sign in to comment.