Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change service config parameters at runtime

I'm using mailgun to send mails thought Laravel 5.2. It configured on config/services.php like that:

    'mailgun' => [
        'domain' => env('mailgun_domain','mydomain.com'),
        'secret' => env('mailgin_secret','my-secret-key-132152345423')
    ],

But, I need change that settings in run time, before call Mail::send, to use the correct service parameters. It must be changed many times during runtime.

I cannot configure it by .env file, because all data will be get from database, where the user setups the domain and secret.

like image 453
Tiago Gouvêa Avatar asked Aug 10 '16 12:08

Tiago Gouvêa


1 Answers

You can set config values dynamically at runtime with config() helper:

config(['services.mailgun' => $arrayWithNewSettings]);
like image 143
Alexey Mezenin Avatar answered Nov 03 '22 19:11

Alexey Mezenin