update github workflow
This commit is contained in:
@@ -4,45 +4,50 @@ namespace App\Providers;
|
||||
|
||||
use App\Http\Facade\SignRSA;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class MailConfigServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
// ✅ Truy vấn an toàn
|
||||
$mail = Setting::where('key', 'smtp')->first();
|
||||
$setting = Setting::where('key', 'setting')->first();
|
||||
if ($mail) {
|
||||
$mail = (object)json_decode($mail->value);
|
||||
|
||||
$config = array(
|
||||
'driver' => $mail->transport,
|
||||
'host' => $mail->host,
|
||||
'port' => $mail->port,
|
||||
'from' => array('address' => $mail->user, 'name' => json_decode($setting->value)->company),
|
||||
if ($mail && $setting) {
|
||||
$mail = json_decode($mail->value);
|
||||
$company = json_decode($setting->value)->company ?? 'Your Company';
|
||||
|
||||
$config = [
|
||||
'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' => $mail->password ? SignRSA::DecryptFunc($mail->password) : ""
|
||||
);
|
||||
'username' => $mail->user ?? '',
|
||||
'password' => isset($mail->password) ? SignRSA::DecryptFunc($mail->password) : '',
|
||||
];
|
||||
|
||||
Config::set('mail', $config);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user