Use the LaravelEnvProviders extension package to load corresponding service providers based on the application development environment. 1. Introduction
Laravel EnvProviders provides a new way for us to manage the loading of Service providers in Laravel applications. With this extension package, we can load specific Service providers in different development environments.
2. Installation
Install with Composer:
Composer require sven/env-providers
Then register the service provider EnvServiceProvider in config/app. php:
// Config/app. php 'Providers '=> [... Sven \ EnvProviders \ EnvServiceProvider: class,];
3. use
You must publish the configuration file of the extension package before use:
Php artisan vendor: publish -- provider = "Sven \ EnvProviders \ EnvServiceProvider"
This command releases the configuration file providers. php in the extension package to the config Directory of the application root directory. In this configuration file, we can see two arrays: load and development_environments.
There are two nested arrays in the load array: providers and aliases. this is the same as in config/app. php. you can register a service provider in providers and register a facade in aliases.
Some default values have been set in development_enviroments. you can modify them as needed. The value must match APP_ENV in. env. then, the application loads the service provider defined in load according to the current development environment set in. env.