1
我使用模型文件获取邮件配置数据,并将其传递给我的提供者名称CofigServiceProvider.php。但我不知道如何将它传递到config/mail.php文件。因为我需要从我的管理面板动态更改邮件配置数据。或任何其他方式在laravel抓取分贝值,并把它传递应用程序/配置/ mail.php 4如何将邮件数据从服务提供者传递到laravel 4中的config/mail.php
ConfigServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Config;
use Home;
class ConfigServiceProvider extends ServiceProvider {
public function register() {
$smtpdata = Home::get_smtp_data();
Config::set('database.connections.mysql.host', $smtpdata->sm_host);
Config::set('database.connections.mysql.port', $smtpdata->sm_port);
Config::set('database.connections.mysql.username', $smtpdata->sm_uname);
Config::set('database.connections.mysql.password', $smtpdata->sm_pwd);
}
}
Home.php(模型)
public static function get_smtp_data()
{
return DB::table('nm_smtp')->where('sm_isactive','=', 1)->first();
}
配置/Mail.php:
<?php
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
/*
'from' => array('address' => null, 'name' => null),
===> */
'from' => array('address' => '[email protected]', 'name' => 'Laravel'),
'encryption' => 'ssl',
'username' => '[email protected]',
'password' => '******',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);