How to define providers that only work in local environment with Laravel 4?

0

In Laravel 4, we have a file called app/config/app.php , which we use to define configuration information that will be used in the application.

When I am in a development environment, I configure the application to process app/config/local/app.php to be able to have information that will be used only in the development environment.

But I have a problem: When I try to add a value in providers to be process only in local environment, I'm getting errors when running Artisan or memso the application.

I imagine this is happening because when we store a configuration file, the indexes of app/config/app.php are replaced by what we use in app/config/local/app.php , and this is probably causing some item of index providers to be removed .

Example app/config/app.php :

'providers' => array(

    'Illuminate\Auth\AuthServiceProvider',
    'Illuminate\Auth\Reminders\ReminderServiceProvider',
    'Illuminate\Cache\CacheServiceProvider',
    'Illuminate\Cookie\CookieServiceProvider',
    'Illuminate\Database\DatabaseServiceProvider',
    'Illuminate\Database\MigrationServiceProvider',
    'Illuminate\Database\SeedServiceProvider',
    'Illuminate\Encryption\EncryptionServiceProvider',
    'Illuminate\Filesystem\FilesystemServiceProvider',
    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
    'Illuminate\Hashing\HashServiceProvider',
    'Illuminate\Html\HtmlServiceProvider',
    'Illuminate\Log\LogServiceProvider',
    'Illuminate\Mail\MailServiceProvider',
    'Illuminate\Pagination\PaginationServiceProvider',
    'Illuminate\Queue\QueueServiceProvider',
    'Illuminate\Redis\RedisServiceProvider',
    'Illuminate\Remote\RemoteServiceProvider',
    'Illuminate\Routing\ControllerServiceProvider',
    'Illuminate\Session\CommandsServiceProvider',
    'Illuminate\Session\SessionServiceProvider',
    'Illuminate\Translation\TranslationServiceProvider',
    'Illuminate\Validation\ValidationServiceProvider',
    'Illuminate\View\ViewServiceProvider',
    'Illuminate\Workbench\WorkbenchServiceProvider',

Example app/config/local/app.php :

'providers' => array(
     'Way\Generators\GeneratorsServiceProvider',
     'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider',
 )

How can I solve this problem?

    
asked by anonymous 06.02.2017 / 14:58

1 answer

0

In Laravel 4, there is a function called append_config , which reindexes a array to a high numbering, starting from 99999 .

This happens because the Config class, by default, writes the arrays of the same indexes present in the configuration files. When you set a local setting, the value set there overrides the original value.

So you could set your app/config/local/app.php file as follows:

'providers' => append_config(array(
     'Way\Generators\GeneratorsServiceProvider',
     'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider',
 ))

To be honest, I found the solution to append_config as much as a nut. So, I preferred to sort by naming the indexes:

'providers' => array(
     'local.generator.provider' => 'Way\Generators\GeneratorsServiceProvider',
     'local.xethron.providers' => 'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider',
 )

In the above case, the appointments will not collide, since by default, the app/config/app.php file uses a array with no index (which makes it sequential and numeric).

    
17.03.2017 / 01:15