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

[Question] Implementation of whereIn operator #3

Closed
bilfeldt opened this issue Oct 30, 2019 · 5 comments
Closed

[Question] Implementation of whereIn operator #3

bilfeldt opened this issue Oct 30, 2019 · 5 comments

Comments

@bilfeldt
Copy link

bilfeldt commented Oct 30, 2019

I am trying to figure out how to implement the eloquent method whereIn in combination with an input field where the input is split by some delimiter.

Imagine a filter like so:

  • Field: id
  • Operator: in
  • Value: "1,2,3"

which would add the following query:

$query->whereIn('id', [1, 2, 3]);

where the array of id's are retrieved as

$values = explode($delimiter=',', $value);

This would make it possible to filter a resource based on an array of id's for example.

Do you have any pointers as how to implement something like this using your package? Thanks.

@dddeeemmmooonnn
Copy link
Owner

Hello.
You can extend dddeeemmmooonnn\NovaMulticolumnFilter\NovaMulticolumnFilter and override apply method

@bilfeldt
Copy link
Author

True, but that would require me to override the apply method, which will break in case of future field types being implemented.

Are you open for a PR for this operator? Or alternatively, might I suggest refactoring the apply method to use a new applySingle in the foreach (json_decode($value, true) as $val) {} loop. In that case, people can simply extend the applySingle method to call their own method if a custom filter is provided and otherwise the parent applySingle.

@dddeeemmmooonnn
Copy link
Owner

dddeeemmmooonnn commented Oct 30, 2019

I think then it is better to add a new option for the column - the name of the method by which to process the column.
Then you will need to add the method and specify it in the options
I'll do it later today

ofc open for PR

@bilfeldt
Copy link
Author

@dddeeemmmooonnn that would be a nice refactoring. When added please let me know and I will check if I can implement this feature, hopefully as a PR. I think it would be a neat addon 👍

@dddeeemmmooonnn
Copy link
Owner

0.5 update

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

No branches or pull requests

2 participants