简体   繁体   中英

Laravel 5 set global variable for config file (mailchimp)

I use mailchimp inside Laravel 5.2 for newsletter. I want the api key and list ID to be set from admin panel, saved in database, and then use dynamic in config file for mailchimp. My problem is I cant query the database inside config. Is there a way to share the variable like in view()->shar e and then be available even in config files?

Since you've made the api key and list ID changeable by user, I think they no longer have anything to do with config or env. I suggest to take them out from config. And then you can get their values with Eloquent:

// Assume your table name is 'settings', with 'code' and 'value' fields
$apiKey = Setting::where('code', 'mailchimp_api_key')->value('value');
$listId = Setting::where('code', 'mailchimp_list_id')->value('value');

And what if i use this:

Config::set('laravel-newsletter.mailChimp.apiKey', $data['mailchimp']['apiKey']);
Config::set('laravel-newsletter.mailChimp.lists.subscribers.id', $data['mailchimp']['listID'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM