@roni I think you'd just need to follow the same steps for your package's composer.json file.
This might be of help: https://laravel-news.com/creating-helpers
I'll point out the importance of using function_exists(), which the link above covers.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
When writing a package, I want to add two helper files to my laravel application.
Normally I'd just pull them in through composer to the proper namespace. Like this in a laravel App
Composer.json
The Following would pull functions in the app/Helpers/BaseHelpers.php into a global scope in the app namespace, and the functions in tests/test-helpers.php into the test namespace.
autoload": {
"psr-4": {
"App\": "app/"
},
"files": [
"app/Helpers/BaseHelpers.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
},
"files": [
"tests/test-helpers.php"
]
},
However, if I'm writing a package and I want a file to be pushed into global scope of the test namespace in the project consuming it, how would you adjust the composer.json in the package?
I see what you're saying. I'm not sure if there is a way of doing that thru composer packages.
You could probably place something like this within your package's service provider:
include_once(__DIR__.'/Helpers.php');
Then define all your global helper functions within that file, wrapping each one in a if function_exists()
I don't see why that wouldn't work.
Please or to participate in this conversation.