· September 1, 2020 · ⋆ Laravel In one of my articles, I’ve described how you can add different behavior to some of the classes in Laravel using macros. To give you a primer, Laravel ships with this trait called Illuminate\Support\Traits\Macroable using which you can add additional methods to the class in hand (which is using the Macroable trait) at run time.
And if you want to add an additional method which doesn’t exist in the class currently, you can do it like so.
As you can see, StrMacros is just a simple PHP class and here, you can create as many macro methods as you may like which will act as methods just like you’d be creating using the macro method.