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

ypppa's avatar

L5 append_config problem

In L5 I'm trying to append dev service providers in app config like in L4 But it seems not to be working. Main app config is totally ignored, so application fails

config\local\app.php :

<?php

return [

    'providers' => append_config([

        'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',

    ]),

];
0 likes
5 replies
acasar's avatar
acasar
Best Answer
Level 13

L5 does not support environment subfolders any more. Most cases can be solved using ENV variables, but in this case there is no official solution yet. Your best bet right now would probably be to create a custom Service Provider and register IDE helper there (as well as any other services that should only be available in specific environment.)

if($this->app->environment('local'))
{
    $this->app->register('Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider');
}
10 likes
mikkolauhakari's avatar

Why not just do this in the AppServiceProvider? Save a service provider.

1 like
aqCSci's avatar

I put the following in AppServiceProvider

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        if ($this->app->environment('local')) { // consider turning this into a method like isDevEnvironment() if you need more logic
            array_map([$this->app, 'register'], config('app.devProviders'));
        }
    }

Then in config/app.php, I have the following:

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,
    ],
    
    'devProviders' => [
        /**
         * Development-Only Providers...
         */
        Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class
    ],
3 likes
ivanhoe011's avatar

You could emulate L4 environment subfolders like this:

  • Create config/<Your Environment Name>/app.php config file like in L4, but without append_config() helper. For example:
<?php
return [
    'providers' => [
            Barryvdh\Debugbar\ServiceProvider::class,
    ],
    'aliases' => [
        'Debugbar' => Barryvdh\Debugbar\Facade::class,
    ],
];
  • And then edit your app/Providers/AppServiceProvider:
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\AliasLoader;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    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);
            }
        }
    }
}

Please or to participate in this conversation.