title: Dynamic mail configuration with values from database [Laravel]
body: <p>I have created a service provider in my Laravel Application <code>SettingsServiceProvider</code>. This caches the settings table from the database.</p>
  
  <pre><code>$settings = $cache-&gt;remember('settings', 60, function() use ($settings)
      {
          return $settings-&gt;pluck('value', 'name')-&gt;all();
      });
  
  config()-&gt;set('settings', $settings);
  </code></pre>
  
  <p><code>settings</code> table:</p>
  
  <p><a href="https://i.stack.imgur.com/7NrFt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7NrFt.png" alt="enter image description here"></a></p>
  
  <p>I am able to echo the value from the table like this:</p>
  
  <pre><code>{{ config('settings.sitename') }}  //returns Awesome Images
  </code></pre>
  
  <p>This works fine on any blade files or controllers in <code>App\Http\Controllers</code></p>
  
  <p><strong>Problem:</strong></p>
  
  <p>I am trying to echo the value to <code>App\config\mail.php</code> like this:</p>
  
  <pre><code>'driver' =&gt; config('settings.maildriver'),
  'host' =&gt; config('settings.mailhost'),
  </code></pre>
  
  <p>But I'm getting this error:</p>
  
  <pre><code>Missing argument 1 for Illuminate\Support\Manager::createDriver()
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>I have created a new service provider <code>MailServiceProvider</code> to override the settings in Mail.php like this:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Providers;
  
  use Illuminate\Support\ServiceProvider;
  use Config;
  
  class MailServiceProvider extends ServiceProvider
  {
      /**
       * Bootstrap the application services.
       *
       * @return void
       */
      public function boot()
      {
          //
      }
  
      /**
       * Register the application services.
       *
       * @return void
       */
      public function register()
      {
          Config::set('mail.driver', config('settings.maildriver'));
          Config::set('mail.host', config('settings.mailhost'));
          Config::set('mail.port', config('settings.mailport'));
          Config::set('mail.encryption', config('settings.mailencryption'));
          Config::set('mail.username', config('settings.mailusername'));
          Config::set('mail.password', config('settings.mailpassword'));
  
      }
  }
  </code></pre>
  
  <p>But still I am getting the same error!!</p>
  
  <p>Is there any way to override default mail configuration (in <code>app/config/mail.php</code>) on-the-fly (e.g. configuration is stored in database) before swiftmailer transport is created?</p>