如何设置动态 SMTP 详细信息 laravel [英] How to set dynamic SMTP details laravel
本文介绍了如何设置动态 SMTP 详细信息 laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理一个项目,我需要在每次管理员登录时更新 SMTP 详细信息.我将详细信息存储在数据库中,最好的方法是什么.
I am working with a project where i need to update SMTP details on every admin login. I am storing the details in database, what is the best way to do that.
推荐答案
我自己的方法:从 config/app.php
中移除 IlluminateMailMailServiceProvider::class
在引导时加载的提供程序列表,并创建一个新的中间件以在识别用户后手动加载它.
My own approach: remove IlluminateMailMailServiceProvider::class
from config/app.php
list of providers loaded at bootstrap, and create a new middleware to load it manually after the user has been identified.
<?php
namespace AppHttpMiddleware;
use IlluminateContractsAuthGuard;
use IlluminateMailTransportManager;
use Closure;
use Mail;
use Config;
use App;
class OverwriteMail
{
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
public function handle($request, Closure $next)
{
/*
$conf is an array containing the mail configuration,
a described in config/mail.php. Something like:
[
'driver' => 'smtp',
'host' => 'smtp.mydomain.com',
'username' => foo',
'password' => 'bar'
...
]
*/
$conf = my_own_function();
Config::set('mail', $conf);
$app = App::getInstance();
$app->register('IlluminateMailMailServiceProvider');
return $next($request);
}
}
来源:http://blog.madbob.org/laravel-dynamic-mail-配置/
这篇关于如何设置动态 SMTP 详细信息 laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文