Question: I need to store some global variables for my laravel website, but I need to update them programmatically. Here is my situation:

[![Part of my admin dashboard, the admin can enable popups when a visitor comes to the website.](https://i.stack.imgur.com/zxK5I.png)](https://i.stack.imgur.com/zxK5I.png)

the admin should be able to enable popups, and configure which post it has to link, which will show when a visitor comes to the website.

**Other answers and why they did not satisfy me.**

* Making a laravel config file.
* A database table.
* Static variable somewhere in a controller or model.

A **Laravel config file** seemed to be the best option at first, but it didn't fit with the need to update them at running time. I've readt answers that suggested to call an artisan cache clear in the controller in order to update the values. but this seems just off to me. I don't think its a good idea to mess with the cache like that.

A **database** is still an option, however, it has some downsides as well. Making just an SQL table for 2 config variables seems like a waste of tables, it also means i need to make 2 query's on the admin dashboard, and also 1 on the homepage (to get the popup config), which i rather keep database-free.

A **static variable in a model or controller**. I saw this suggestion as well altough noted: it is probably a very bad design choice. Nevertheless i tried it in a desperate attempt and it didnt work. It did not stay updated on page reload.

I'm a laravel noob in case you didn't notice. Is there anything I am doing or understanding wrong? Or is there a solution I am not aware of?

*There is no need for me to save the variable when the website is offline. It would be nice if it did but its only a minor inconvience for the admin to set it on restart.*

Answer: 
Use a db table to store the configuration, also having one extra table does not have any serious downside and it won't hurt the performance, also most popular applications/frameworks use it.

To reduce the db queries, create a wrapper class for your db config load, and in your wrapper cache the data for some amount of time, and when you want to change the config, remember to invalidate the cache.

If you want global access to it, bind it to laravel service provider, and use Facade or other container methods to fetch it. Also with this approach you keep the exposed config interface the same even if you change the implementation different in future.

About file solution: If you have one admin, you can go with file solution, but you never know how they will grow in numbers in future and it will be a hassle to go around what you did in file.
You can set config values dynamically at runtime with [`config()`](https://laravel.com/docs/5.2/helpers#method-config) helper:

```
config([ 'app.popup1' => true ]);

```

Another solution is to write the config value into [session](https://laravel.com/docs/5.2/helpers#method-session) at startup and only update the session:

```
session([ 'app.popup1' => true ]);

```