-
-
Notifications
You must be signed in to change notification settings - Fork 530
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
[5.x] Add select modifier #10183
[5.x] Add select modifier #10183
Conversation
Does the Pluck modifier not do the same thing? https://statamic.dev/modifiers/pluck |
Similar. Pluck grabs a single value and flattens the array. What he's proposing is to maintain the associative array but only specific keys in each. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this modifier should be called select
. Copying Collection's select
method:
https://laravel.com/docs/11.x/collections#method-select
Collection's only
method works differently.
Ahh, thanks for the clarification! Carry on 🤘 |
Ah yeah good catch. Only is for filtering a single level array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can probably also use ->select()
on the collection now.
I don't believe that works when the items don't implement $items = $value->select($keys); And a bunch of the tests fail. I think that is why the return method_exists($item, 'value') ? $item->value($key) : $item->get($key); |
Fair! |
Sometimes it is useful to do more than just pluck a single set of values from an array/collection of items.
Similar to Laravel's
Arr::only
this PR adds anonly
modifier to handle those cases where you need more than one key.Example Data:
Example Template:
Example Output: