Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zer0uno's avatar

zer0uno started a new conversation+100 XP

5mos ago

In Laravel 12 how can I load different service providers based on the environment? I think the documentation is lacking on this topic.

So far I've found 3 potential places:

  • inside the bootstrap/providers.php using app()->environment() BUT in case of "php artisan make:provider" it will be overwritten
  • inside the config/app.php under the "providers" key BUT I'm not sure if this property is still supported because I can find to reference in the docs, I've just found it looking at the source code
  • inside the specific service provider calling $this->app->environment() BUT it requires the logic to be replicated in each service provider