In this post to his site Nicola Malizia briefly helps you understand the Laravel "macroable" trait - what it is and how to can be used in your own code.
If you check the Laravel codebase I’m sure that you can observe that Laravel makes use of traits.There is one trait in the source code that pulls my attention. I’m talking about the Macroable trait. In case you don’t know, you can define custom responses using macros.
He includes an example of extending the default Response
class with a "caps" macro and how it would then be used in the resulting object. He talks about how traits work in PHP OOP code and how they can be used to "inherit" functionality into a class. The "macroable" trait then uses the __call
magic method to do its thing, looking for macros that match the function being called.