Dynamically Register a Service Provider

app()->register('App\Providers\MyCustomServiceProvider');

If you ever need to dynamically load a Service provider in your laravel application you can do so with the following line of code:

app()->register('App\Providers\MyCustomServiceProvider');

Make sure to add the correct namespace to your Custom Service Provider and it will dynamically be added when that line of code from above is executed.

This can come in handy if you have a bunch of Service Providers and not all of them need to be added with every application request.

BETA Snippet explanation automatically generated by OpenAI:

No explanation generated yet.

Snippet By Dev Dojo

·

Created June 12th, 2021

·

Report Snippet