A
A
Anton2016-12-28 16:49:11
Laravel
Anton, 2016-12-28 16:49:11

How to correctly use the prepend method on the Config facade?

Good afternoon!
There is a config/database.php file (standard in the framework). Here is a piece of code:

return [
    'connections' => [
        'builder.ru' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'test'),
            'username' => env('DB_USERNAME', 'test'),
            'password' => env('DB_PASSWORD', 'test'),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ]
    ],
];

Using the framework functions, you can add data to an array (any, as I understand it). Here is the documentation for this part - https://laravel.com/api/5.3/Illuminate/Config/Repo...
Tried adding new data like this:
Config::prepend('database.connections', [
    'test.ru' => [
        'driver' => 'mysql'
    ]
]);

No matter how you try, any attempt seems to be ignored. The file has a use Config, so the problem is definitely not in the file connection.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2016-12-28
@Yadalay

Судя по коду, этот класс вообще ничего на диск не пишет, поэтому вам и кажется, что ничего не работает. Поищите в исходниках как записать значения на диск (ну или просто пишите через file_put_contents(var_dump($cfg)));;

Дмитрий, 2016-12-29
@Astatroth

Config меняет занчения только для следующего запроса. Если хотите сохранять изменения конфигов - используйте сторонний пакет, этот например.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question