refactor: Cache mail configuration, update route domains to use config() helper, and upgrade developer dependencies.

This commit is contained in:
pbao9
2026-03-17 11:44:42 +07:00
parent 50a5bfd530
commit 017248eeb9
8 changed files with 572 additions and 558 deletions
Vendored
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+14 -10
View File
@@ -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);
}
}
+4 -4
View File
@@ -39,26 +39,26 @@ class RouteServiceProvider extends ServiceProvider
$this->routes(function () {
// 1. Agency API — domain riêng → chỉ client.php
Route::domain(env('API_AGENCY_URL'))
Route::domain(config('app.api_agency_url'))
->middleware(['api', 'json.response'])
->namespace($this->namespace)
->group(base_path('routes/client.php'));
// 2. System API — bind về APP_URL
Route::domain(env('APP_URL'))
Route::domain(config('app.url'))
->prefix('api')
->middleware(['api', 'json.response'])
->namespace($this->namespace)
->group(base_path('routes/api.php'));
// 3. Admin Backend routes
Route::domain(env('APP_URL'))
Route::domain(config('app.url'))
->middleware('web')
->namespace($this->namespace)
->group(base_path('routes/admin.php'));
// 4. Web routes
Route::domain(env('APP_URL'))
Route::domain(config('app.url'))
->middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
+3 -3
View File
@@ -19,10 +19,12 @@
"laravel/horizon": "^5.4.0",
"laravel/tinker": "^2.7",
"maatwebsite/excel": "^3.1",
"nunomaduro/collision": "^7.12",
"opcodesio/log-viewer": "^3.18",
"phpseclib/phpseclib": "*",
"predis/predis": "^2.2",
"pusher/pusher-php-server": "^7.2",
"spatie/laravel-ignition": "^2.9",
"spatie/laravel-permission": "^6.3",
"spatie/laravel-sluggable": "^3.7",
"tymon/jwt-auth": "^2.0"
@@ -31,9 +33,7 @@
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.1",
"phpunit/phpunit": "^9.5.10",
"spatie/laravel-ignition": "^2.0"
"phpunit/phpunit": "^9.5.10"
},
"autoload": {
"psr-4": {
Generated
+549 -541
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -57,6 +57,8 @@ return [
'url' => env('APP_URL', 'http://localhost'),
'api_agency_url' => env('API_AGENCY_URL'),
'asset_url' => env('ASSET_URL', null),
/*
BIN
View File
Binary file not shown.