我使用模型文件获取邮件配置数据,并将其传递给我的提供者,名称为CofigServiceProvider.php。但我不知道如何将其传递到config / mail.php文件中。因为我需要从管理面板动态更改邮件配置数据。或任何其他方式获取db值并在laravel 4中传递app / 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' => 'myaccount@gmail.com', 'name' => 'Laravel'),
'encryption' => 'ssl',
'username' => 'myname@gmail.com',
'password' => '******',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
答案 0 :(得分:1)
Jus更新您的ConfigServiceProvider,例如
<?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('mail.host', $smtpdata->sm_host);
Config::set('mail.port', $smtpdata->sm_port);
Config::set('mail.username', $smtpdata->sm_uname);
Config::set('mail.password', $smtpdata->sm_pwd);
}
}