Laravel Config Values From Database Setting Table Hello Friends,
I want to ask about laravel config values from the database table name "site_settings";
I want to get all configuration values from the "site_settings" table.
Like:
DB_DATABASE
DB_USERNAME
DB_PASSWORD
MAIL_USERNAME
MAIL_PASSWORD
Google client_id
Google client_secret
Google redirect etc.
Which way is best to do this?
Plz, Help me.
Thanks
does the table have an associated "configuration" class? I didn't test it but if so I believe you can edit config/database.php and add your values like Configuration::where('key', 'nameofit')->first()->pluck('value')
if indeed your columns are named key and value
@NemoPS Thanks
E.g
I have stored DB_USERNAME & DB_PASSWORD in the site_settings table.
Now I want to get DB_USERNAME & DB_PASSWORD in the .env file OR in the config file in laravel.
How can I do this?
I would really not recommend storing the db information your database.
Laravel has built in features to interact with configuration values, you can get and also set them
https://laravel.com/docs/9.x/configuration#accessing-configuration-values
So what you could do is just create a from and set those config values and just access them where you need it in your views or where ever you need it
@Levente_N Thanks
Is there any way to store all values of site_setting in the config in array & get these values according to requirement?
@msaad
Example:
You have your form right? that form has an input named site_settings
When you submit the form you can do this to set that config value
config('settings.site_name', $request->input('site_name'));
then to access it you just call config('settings.site_name');
same can be applied for your google secret and others
Or is any way to store values in cache and use these values.
Please sign in or create an account to participate in this conversation.