Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Pineco.de:
Extending Laravel’s Collection With Macros
Jul 20, 2018 @ 14:43:29

On the Pineco.de blog they've posted a new tutorial showing how to extend the Collection functionality of Laravel with the help of macros.

Collections are fantastic features of the framework. With the functionality that the collection offers, we can easily handle any need that a dataset requires. But still, in some cases, we may extend with custom functionality.

The post starts with a more general look at what collection macros are and a few code snippets of them in action. To illustrate how to extend them, they create a "some" macro that takes in an anonymous function containing some kind of logic to check the key/value passed to it and return a boolean. The post finishes up by linking to the macro documentation and another package that implements a wide range of additional macros (like "extract", "paginate", "tail" and "transpose").

tagged: laravel collection macro tutorial some extend

Link: https://pineco.de/extendig-laravels-collection-with-macros/