refactor: Cache mail configuration, update route domains to use config() helper, and upgrade developer dependencies.
This commit is contained in:
@@ -5,6 +5,7 @@ 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;
|
||||
@@ -18,25 +19,26 @@ class MailConfigServiceProvider extends ServiceProvider
|
||||
|
||||
public function boot()
|
||||
{
|
||||
// 🔐 Không làm gì nếu đang chạy trong CLI (migrate, cache:clear, ...)
|
||||
if (App::runningInConsole()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// ⛔ Tránh lỗi nếu database hoặc bảng `setting` chưa tồn tại
|
||||
if (!Schema::hasTable('setting')) {
|
||||
return;
|
||||
}
|
||||
$config = Cache::remember('mail_config', 3600, function () {
|
||||
if (!Schema::hasTable('setting')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// ✅ Truy vấn an toàn
|
||||
$mail = Setting::where('key', 'smtp')->first();
|
||||
$setting = Setting::where('key', 'setting')->first();
|
||||
$mail = Setting::where('key', 'smtp')->first();
|
||||
$setting = Setting::where('key', 'setting')->first();
|
||||
|
||||
if (!$mail || !$setting) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($mail && $setting) {
|
||||
$mail = json_decode($mail->value);
|
||||
$company = json_decode($setting->value)->company ?? 'Your Company';
|
||||
|
||||
$config = [
|
||||
return [
|
||||
'driver' => $mail->transport ?? 'smtp',
|
||||
'host' => $mail->host ?? '',
|
||||
'port' => $mail->port ?? 587,
|
||||
@@ -48,7 +50,9 @@ class MailConfigServiceProvider extends ServiceProvider
|
||||
'username' => $mail->user ?? '',
|
||||
'password' => isset($mail->password) ? SignRSA::DecryptFunc($mail->password) : '',
|
||||
];
|
||||
});
|
||||
|
||||
if ($config) {
|
||||
Config::set('mail', $config);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user