如何在Laravel 4中将邮件数据从服务提供商传递到config/mail.php [英] How to pass mail data from service provider to config/mail.php in laravel 4

查看:52
本文介绍了如何在Laravel 4中将邮件数据从服务提供商传递到config/mail.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用模型文件获取邮件配置数据,并将其名称传递给我的提供者CofigServiceProvider.php.但是我不知道如何将其传递到config/mail.php文件中.因为我需要从管理面板动态更改邮件配置数据.或任何其他方式来获取db值并将其传递给laravel 4中的app/config/mail.php

I was fetch mail configuration data using model file, and pass it to my provider the name CofigServiceProvider.php. But i don't know how to pass it into config/mail.php file. Because i need to change the mail configuration data dynamically from my admin panel. or Any other way to fetch db values and pass it app/config/mail.php in laravel 4

ConfigServiceProvider.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(模型)

Home.php(model)

public static function get_smtp_data()
{
    return DB::table('nm_smtp')->where('sm_isactive','=', 1)->first();
}

config/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,

 );

推荐答案

Jus像这样更新ConfigServiceProvider,

Jus update your ConfigServiceProvider like,

<?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);
}
}

这篇关于如何在Laravel 4中将邮件数据从服务提供商传递到config/mail.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆