Source: ryangjchandler.co.uk

Macros in Laravel
Laravel's Illuminate\Support\Macroable trait allows you extend classes at runtime with custom methods. The idea is that you provide a named Closure, or callable value, which can then be invoked using PHP's __call() and __callStatic() magic methods.

The Collection object is known for it's fluency and method chaining and this bit of code doesn't fit into that pattern.

We can now call a magic path() method on the $collection and it will return the value found at the path provided. $baz = collect([ //... ]) ->path('foo.bar.baz'); Behind the scenes the method call is being delegated to the __call() method implemented by the Macroable trait.
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