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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners