如何设置动态 SMTP 详细信息 laravel

Jyo*_*hra 3 smtp laravel

我正在处理一个项目,我需要在每次管理员登录时更新 SMTP 详细信息。我将详细信息存储在数据库中,最好的方法是什么。

mad*_*bob 6

我自己的方法:Illuminate\Mail\MailServiceProvider::classconfig/app.php引导程序加载的提供程序列表中删除,并创建一个新的中间件在用户被识别后手动加载它。

<?php

namespace App\Http\Middleware;

use Illuminate\Contracts\Auth\Guard;  
use Illuminate\Mail\TransportManager;

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('Illuminate\Mail\MailServiceProvider');

        return $next($request);
    }
}
Run Code Online (Sandbox Code Playgroud)

来源:http : //blog.madbob.org/laravel-dynamic-mail-configuration/