Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to enable filters to work with empty values #200

Merged
merged 4 commits into from
May 7, 2024

Conversation

james-waring
Copy link
Contributor

Hello, This is my first pull request so if there is anything i have missed please explain so i can learn.

I working on a project where i need to filter the model even when the value is an empty array.

I have added a simple config value that will simply return the passed in input in removeEmptyInput.

If there is a better way you would like to do this would you still add it to the project?

@Tucker-Eric
Copy link
Owner

Hey @james-waring !

Thanks for the PR! I like the idea behind it. Do you think we'd be able to have the configuration live on the filter itself instead of in the config? I like the granular control you'd be able to have by just enabling it for filters your interested in.

@james-waring
Copy link
Contributor Author

Hi, I like that idea too.

I have updated the code, it now has an array property called allowedEmptyFilters on the ModelFilter.

When the filterInput function runs i now add the method name that was called to a calledMethods array so when the allowedEmptyFiltersInput function runs it will run the filters that are in the array allowedEmptyFilters but only if the method name is not in the calledMethods array.

As im not sure if i can get what methods have been called from the eloquent query builder i have done it this way for now. If this can be done then it probably would be better to swap it out to this code.

I have added the test testAllowedEmptyFilter but i had to leave it as a todo because i cant work out how to do it as i think the best thing to test is the query builder to make sure the method was called.

Let me know what you think?

@Tucker-Eric
Copy link
Owner

@james-waring , I added the tests and update the property to be boolean on the model filter to conditionally filter out the empty input when true.

@Tucker-Eric Tucker-Eric merged commit 4790962 into Tucker-Eric:master May 7, 2024
8 checks passed
@Tucker-Eric
Copy link
Owner

@james-waring published under the 3.4.0 tag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants