Collection select() #41521
Unanswered
roberto-butti
asked this question in
Ideas
Collection select()
#41521
Replies: 3 comments 2 replies
-
There is already a method that does what you want, although it is called |
Beta Was this translation helpful? Give feedback.
2 replies
-
There was a discussion before about this specific case. |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can use a combination of $collection->map->only(['product', 'price']); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When you have a bi dimensional array like this one (an array of associative arrays):
You can apply method for filtering (where()), sorting (sortBy()) and so on ...
If you want to select and "pick" just few keys or columns or fields, probably, as a developer, you want to use a method to specify the keys you want:
I would like to suggest implementing "select()" method where the developer can define a list of keys to "extract".
Think to a bi- dimensional array like a db table where you have columns, and you need to perform a select operation to select just some columns.
The result is something like that:
I could have the code already implemented. I added also the static method to Arr class.
If you agree with this suggestion, I can open a PR, if not: "amici come prima 🇮🇹 " 🥳
Beta Was this translation helpful? Give feedback.
All reactions