In all Laravel versions, if we want to register a new service provider, we can open the config/app.php
file and add the new provider to the providers
array, like so:
'providers' => [
...
Path\To\New\ServiceProvider::class,
],
My idea is to install a package and have it automatically load its service provider, so without a need to add the new provider to the Laravel's app.php
I have two questions:
- Is this a good idea? In both cases, why is it good / not good?
- Is there a preferred way of doing this? My guess is to autoload a bootstrap file from the package's
composer.json
, and then$this->app->register('Path\To\New\ServiceProvider');
from there.
Is this how it should be done?
As advised by Sven, I'm adding information to clarify what I intend to achieve.
I'm planning to create a core package which would manage adding (installing) and removing its dependant auxiliary packages from a remote repository. For that I would like to have complete autonomy for the auxiliary packages, meaning that 100% of everything related to an auxiliary package should be stored within that package's folder, with an option for users to publish and customize its /resources, as expected in a Laravel app.