60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Http\Facade\SignRSA;
|
|
use App\Models\Setting;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class MailConfigServiceProvider extends ServiceProvider
|
|
{
|
|
public function register()
|
|
{
|
|
//
|
|
}
|
|
|
|
public function boot()
|
|
{
|
|
if (App::runningInConsole()) {
|
|
return;
|
|
}
|
|
|
|
$config = Cache::remember('mail_config', 3600, function () {
|
|
if (!Schema::hasTable('setting')) {
|
|
return null;
|
|
}
|
|
|
|
$mail = Setting::where('key', 'smtp')->first();
|
|
$setting = Setting::where('key', 'setting')->first();
|
|
|
|
if (!$mail || !$setting) {
|
|
return null;
|
|
}
|
|
|
|
$mail = json_decode($mail->value);
|
|
$company = json_decode($setting->value)->company ?? 'Your Company';
|
|
|
|
return [
|
|
'driver' => $mail->transport ?? 'smtp',
|
|
'host' => $mail->host ?? '',
|
|
'port' => $mail->port ?? 587,
|
|
'from' => [
|
|
'address' => $mail->user ?? 'no-reply@example.com',
|
|
'name' => $company,
|
|
],
|
|
'encryption' => $mail->encryption === 0 ? 'tls' : $mail->encryption,
|
|
'username' => $mail->user ?? '',
|
|
'password' => isset($mail->password) ? SignRSA::DecryptFunc($mail->password) : '',
|
|
];
|
|
});
|
|
|
|
if ($config) {
|
|
Config::set('mail', $config);
|
|
}
|
|
}
|
|
}
|