Depending on how many helper functions you intend to move over, I suggest two options:
- Create app/Http/helpers.php and move all of your functions into there
- Add the helpers.php file to your composer.json autoload files
{
"autoload": {
"files": [
"app/helpers.php"
]
}
}
However, if you have a lot of helper functions or they contain a large amount of logic, I'd suggest creating helper files foreach individual functionality:
- Create app/Http/Helpers/TranslatedStringHelper.php and add the corresponding function(s)
- Create a new HelperServiceProvider.php and add loop to dynamically require helpers
public function register()
{
foreach (glob(app_path().'/Helpers/*.php') as $filename){
require_once($filename);
}
}
- Register the service provider in your config/app.php
'providers' => [
'App\Providers\HelperServiceProvider',
]
In both cases, you should now be able to use the functions define within the helper file(s) you have created. Using just one file to contain all of your helper functions can become hard to maintain so I'd suggest the latter as it is a more object oriented approach.