This code allows you to register additional package providers and aliases for different environments, similar to how it used to work in L4. While the most of local configuration in L5 can be done by .env files, you can't really separate dev packages that way. If you install a package with `composer require --dev` it will not be available in the production and if you forget to remove the providers from the app.php it will break everything. With this code you can have local/app.php config with package providers and aliases that will be merged with the main config, but only if you are in local env. It will also support using separate config for production/app.php or test/app.php (or any other environment name you use).
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\AliasLoader;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
}
public function register()
{
$path = $this->app->environment() .'.app';
$config = $this->app->make('config');
$aliasLoader = AliasLoader::getInstance();
if ($config->has($path)) {
array_map([$this->app, 'register'], $config->get($path .'.providers'));
foreach ($config->get($path .'.aliases') as $key => $class) {
$aliasLoader->alias($key, $class);
}
}
}
}