JoaoHamerski's avatar

[SERVER/PHP] Is it safe to change config variables at runtime?

For example, i have many database files on my server, they are the same the only thing that changes is the language, so i want to put a option to user choose the language and so i change de config of my config/database.php in 'connections' => [ 'sqlite' => 'database' .... to the path of the database that correspond to the language the user choose, but, i do it on my controller with config(['database.connections.sqlite.database' => $this->getDatabasePath($lang)]) is it safe? Can it have conflict if two of more users choose two or more different langauges at same time? Or each application run a complete different instance in each client machine?

0 likes
3 replies
MichalOravec's avatar

Why you don't have languages table in your database, and everywhere you need it just add foreing key language_id?

It seems to be, that everytime will be choosen database by language, so it couldn't be problem with conflicts.

JoaoHamerski's avatar

I have a databases table where i have lang column and filename column, each file has a different name. But i did this way because when i call DB::connection('sqlite') i need to have a database file in my 'database' key of database.php file, right? This is why i'm changing config variable at runtime, or there is another way to set the database file when i call DB::connection('sqlite')?

JoaoHamerski's avatar

The way i found is that: I set the config file just before call DB::connection('sqlite')

Please or to participate in this conversation.