[9.x] Add keyBy() method to Arr helpers#41029
Conversation
|
About naming, same behavior exists on Collection, its named |
Yes true! I can change the name of the method to leave both with the same behavior. It would be interesting for the Arr class to also have this method. |
|
If this array helper and the collection function are supposed to do the same we maybe should simply use collect($array)->keyBy('id')or if merged update the |
|
If we already have a collection method that does the exact same thing then this method should be named the same as well. |
Hello, I refactored the method to use the function that already exists in the collection. Let Me know if anything is missing. |
Yes, I made the change so that the method uses the existing function in the collection |
Hi guys, this is my first PR. Please let me know if you have anything to change or improve. This method was inspired by the ArrayHelper::index of the Yii2 framework. I used this method a lot to format arrays and I would really like laravel to have it too
Indexes the array according to a specified key.
use case
The result will be an associative array, where the key is the value of id attribute