Nicola Malizia has written up a tutorial that helps to explain Laravel's HighOrder collection functionality, a feature that was added in Laravel 5.4.
A new version of Laravel is available from 24 January 2017 and, as usual, it comes with a lot of new features.Among them, there is one that takes advantage of the dynamic nature of PHP. Some out of there will contempt this, but I find it awesome!
He talks briefly about what the normal Collection class provides and provides an example of creating a collection and using the "map" function to return an average. With the new functionality the methods can be called directly on the collection with a simplified format. With the example out of the way he then dives into the source code for the feature, showing how it defines the "proxy" methods allowed and uses the __get
and __call
magic methods to map the method calls back to a collection.