luisferfranco's avatar

What is the best way to store app parameters/settings? Is there any package?

I have this app that has some events depending on the week number. The week number doesn't depend on the natural calendar. so in my events table I have a column named "week" that goes from 1 to n.

Currently I have another table called "control" which have "key" and "value" columns. One of the records is key -> currentWeek, and value -> whatever it is, and I update the currentWeek every time is needed. This table is of course stored in the main database.

This has work for several years and I really don't have the necessity to change, but I was wondering if there's a better way to do this.

I want to try something new because I only save the app parameters like that, but now I want to give the user the chance to save some custom values for them, and I'm planning on extending this way of work by adding a user_id column, so I'll know when the setting is for the app, and when is for a specific user

0 likes
4 replies
webrobert's avatar

For things that dont change very much you can add them to the config directory...

you can make your own array in the config folder in app OR make your own file there.

then you can use the config helper config('app.the_settings_array.item') as normal.

Otherwise, you can create a settings table in the database (so you can edit things)

For use settings that relate to the app I make a table user_settings and then when a user is created I automatically add a settings row for them with defaults.

1 like
luisferfranco's avatar

@webrobert Is it possible to change what is in the .env file? I use it to store things like API keys and such, things that will never change Good idea about the user_settings table, much cleaner than storing settings with the app settings Thanks!

Sinnbeck's avatar

@luisferfranco the env file is just a text file so you just add the credentials to it and call them from a config file. That's the idea behind the env file

Please or to participate in this conversation.