Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

garrettmassey's avatar

Expanding on Laravel's helper functions

I am starting to use some of Laravel's helper functions, specifically the Array helper functions Arr::. But there are some specific array operations that I want to add to the built-in helpers.

Is there a way to add my own methods to the Arr class or the helpers.php file in the framework without actually editing the files in the /vendor directory?

If not, I'm fine with creating my own helper classes and using the Service Provider to autoload the class, but it would be nice if I could expand on the already existing class names.

0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

The Arr class is macroable, so yes, you can add your own functions:

Arr::macro('foo', function ($array) {
		// implement foo...
});
2 likes

Please or to participate in this conversation.