Tucker-Eric / EloquentFilter

An Eloquent Way To Filter Laravel Models And Their Relationships
http://tucker-eric.github.io/EloquentFilter
MIT License
1.72k stars 120 forks source link

Filter out [ 0 => null ] parameters by default #79

Closed alexjohndoe closed 6 years ago

alexjohndoe commented 6 years ago

When send request using types[]=, the received input is:

[
    0 => null,
]

Which will go into the filter methods.

This is not wanted.

Tucker-Eric commented 6 years ago

Technically that is the desired behavior and the check should lie in the filter method for that input or you can remove it in the setup method of the filter. #58 gives some insight as to why I wouldn't want to check or exclude values based on the content of an array.

If you want to not forward that to the filter method that handles that input you can add an input filter to your setup method:

public function setup()
{
    $this->input = array_filter($this->input, function($val) {
        return !(is_array($val) && count($val) === 1 && $val[0] === null);
    });
}
alexjohndoe commented 6 years ago

@Tucker-Eric Thanks for the reply. 💯