Why do you need them in the database and not the .env file? You start by asking how and then jump straight into using the database? What is the use-case?
How to securely and practically right retrieve information from database and assign it to config varaible?
Hey!
I'm currently storing some necessary API keys for the app inside the .env file. I'm also retrieving them directly from there which won't work in production as I know. So I need to migrate them through some config file but the problem is I want to retrieve these API keys from the database. But I'm afraid I'm not sure I'll be able to do it right. The following goes through my head:
inside any config file (I'll probably use the config/services.php):
'recaptcha' => [
'key' => DB::table('general_settings')->where('id', 1)->value('google_recaptcha_public_key'),
'secret' => DB::table('general_settings')->where('id', 1)->value('google_recaptcha_secret_key'),
],
'stripe' => [
'key' => DB::table('general_settings')->where('id', 1)->value('stripe_public_key'),
'secret' => DB::table('general_settings')->where('id', 1)->value('stripe_secret_key'),
],
Is that practically OK? Will that work in production? Will php artisan config:cache cache this properly? Looking for suggestions!
@Laralex It depends if you have a library (for instance) that is expecting to get the values from config
Otherwise yes, just get the value from the DB direct.
You could improve it though by having your own settings provider that cached the data
Please or to participate in this conversation.