when I try to change the env variable in the code during runtime it does not work and gives me the old variable.
I tried
\config(['rabbitmq.worker' => 'default']);
and also
Config::set('rabbitmq_worker','default');
then when I call env('RABBITMQ_WORKER') it gives me null
Hello Johnabil, I might be wrong but I guess you are messing something up. When you set something with Config facade or config function you are changing the value that comes from the config file, and you are trying to get the value in the last sentence from .env file or system variables, they are two different things.
Your config file uses the .env file to get some variable from the .env file or from the system variables. But it doesn't mean it is gonna work the other way around.
If you want to get the value from config that you have set before, you should use config('key') or Config::get('key').
Remember config file uses the .env file or system variable to set some of its values.
I tried it with config('rabbitmq.worker') in the queue.php in config folder but it didn't work too
Your description is unclear what doesn't work.
But the point is:
Hello,
Just to clarify, when you set a value with Config facade or config function the changes are valid only in the same request, I noticed you are trying to use RabbitMQ, right? This service runs in a separate process, am I right? You should have in mind when you change something with config() or Config::set() it changes only and exclusively in the same request/process/run time execution, it doesn't change if you try to start a new process nor if in an existent running process,
For example: you set a config key value and try to get its new value from a queue process or new request, it is not gonna work.
@mfn @juliano-barros Thanks
Most helpful comment
Hello,
Just to clarify, when you set a value with Config facade or config function the changes are valid only in the same request, I noticed you are trying to use RabbitMQ, right? This service runs in a separate process, am I right? You should have in mind when you change something with config() or Config::set() it changes only and exclusively in the same request/process/run time execution, it doesn't change if you try to start a new process nor if in an existent running process,
For example: you set a config key value and try to get its new value from a queue process or new request, it is not gonna work.