I recently published a deep-dive look at the difference between Laravel Collections and standard PHP functionality on Hackernoon.
Have a look!
https://hackernoon.com/illuminate-collections-vs-php-arrays
I recently published a deep-dive look at the difference between Laravel Collections and standard PHP functionality on Hackernoon.
Have a look!
https://hackernoon.com/illuminate-collections-vs-php-arrays
For further actions, you may consider blocking this person and/or reporting abuse
westtan -
Sarah Siqueira -
Roberto B. -
Nasrul Hazim Bin Mohamad -
Top comments (2)
The biggest difference between Laravel collections and php is that you can add your own methods. I think that is more important than a fluent api.
The code of the examples doesn't show how a collection is more readable. Even the all together example looks very readable. The only thing I would change are the variable names to make it clear what the flow is.
Naming things, even just with a letter, is very powerful. In this case to establish a flow. When there is a letter out of place you will notice it.
If a collection/array requires a lot of actions, why not check if the actions can be reduced before it gets to that part of your code, for example with a data object.
In short I think most of the time there is a better solution than relying on a Collection instance.
I builded many collection classes and often the simplest way is just a array with phpdocs. 😜 chatgpt.com/share/671d8a50-aa5c-80...