Registering a Service Provider With the Application


You want to register a service provider with your application.


Add a class name to the providers[] array in app/config/app.php.

This is the normal way to load service providers. You add the name to the end of the array in app/config/app.php.

'providers' => array(

Then, during the bootup portion of your application, Laravel will determine if the service provider is deferred. If not it will call your service provider's register() method and later, when the application boots, it will call your service provider's boot() method.


You can register service providers directly with App::register().

This is a low level function.

You can call it with the name of your provider class, or an actual instance of the class.


// or
$provider = new MyApp\Providers\MyServiceProvider;

This will immediately call your provider's register() method and if the application has been booted it will call the boot() method.

Generally, the method of adding the provider to the app/config/app.php is a better technique of adding service providers because it keeps all your providers in one location, easily managed.

comments powered by Disqus