Update STMP config on the fly in Laravel 5.1

2019-08-10 17:11发布

My mailing functionality works by adding the configs on .env file.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=username
MAIL_PASSWORD=passwordd
MAIL_FROM=info@text.com
MAIL_NAME=Info

But my problem is I don't know how to update this configs dynamically. I've try using the helper config() but I can't see the SMTP values in config('app').

In case you're wondering why I want to do this is because the SMTP configs will come from the DB.

I hope this is clear, if not please let me know!

Thank you in advance!

1条回答
干净又极端
2楼-- · 2019-08-10 17:50

Perhaps you can use the Config::set method, as answered here:

Config::set('key', 'value');

https://stackoverflow.com/a/23438548/385402

but I think it would be better to use DB values directly before sending the email, I don't know if it makes sense that you store them into a config file at all if you already have them in the database.

查看更多
登录 后发表回答