Dynamic mail configuration with values from database [Laravel]

后端 未结 3 1626
傲寒
傲寒 2021-02-01 07:09

I have created a service provider in my Laravel Application SettingsServiceProvider. This caches the settings table from the database.

$settings = $         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-01 07:54

    Struggled for 3 days with this issue finally I figured out a way to solve it.

    First I created a table mails and populated it with my values. Then I created a provider MailConfigServiceProvider.php

    first();
                if ($mail) //checking if table is not empty
                {
                    $config = array(
                        'driver'     => $mail->driver,
                        'host'       => $mail->host,
                        'port'       => $mail->port,
                        'from'       => array('address' => $mail->from_address, 'name' => $mail->from_name),
                        'encryption' => $mail->encryption,
                        'username'   => $mail->username,
                        'password'   => $mail->password,
                        'sendmail'   => '/usr/sbin/sendmail -bs',
                        'pretend'    => false,
                    );
                    Config::set('mail', $config);
                }
            }
        }
    }
    

    And then registered it in the config\app.php

    App\Providers\MailConfigServiceProvider::class,
    

提交回复
热议问题