Category: Laravel, PHP, javascript

· 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.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners