Reputation: 1
I want to set some environmental variable/config variable via Controller. I have some form in admin panel and when I submit these from after storing the data in the database table I want to use these variable instead of the current .env file. I tried
config(['app.name'=>$setting->site_name]);
in controller but not working.
I also tried
Config::set('app.name',$setting->site_name);
but not working.
When i Run config(['app.name'=>$setting->site_name]);
in my view this will change only for this view (runtime change).
But I want to change for whole application such as how WordPress installation work I want to set my database variable from a form input.
how developers set variable using form In codecanayon laravel application?
I tried this link but not working for me. How to set .env values in laravel programmatically on the fly
Can Anyone help me? Thanks in advance.
Upvotes: 0
Views: 1600
Reputation: 12470
You're only making changes to the configuration which will only be available for the rest of that request. The .env
file is simply the starting point from where the configuration is loaded on each request. It is not recommended that you adjust the .env
file as you are not supposed to adjust the environment from your app. Generally you shouldn't adjust your configuration in realtime either as it means you can't cache it.
If you need to persist data through requests, put it in your database or in a Redis cache.
Upvotes: 1