There are many questions regarding loading custom helper classes in Laravel. However, none of them focus on the loading them with proper initialization.
As of Laravel version 5.3 we can use psr-4 autoloading which is autoloading the entire app/
directory. However, classes are loading but never initialized.
I have my helper class inside the app/helpers/support.php
. This class has a constructor, where I want to load some important configuration in order to make the helper usable.
So how can I load my helper but ALSO initialize it properly in Laravel? Right now I am simply working-around the problem by using new \App\Helper\Support();
inside AppServiceProvider.php
.
Edit: I'm using the following approach to maintain my helper class: