62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Setting;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Throwable;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
$this->applyDashboardDomain();
|
|
}
|
|
|
|
/**
|
|
* Keep Laravel's URL generation in sync with the dashboard-set panel domain
|
|
* WITHOUT ever touching .env.
|
|
*
|
|
* The panel domain lives in the DATABASE (Settings: `dashboard_domain`), not in
|
|
* .env — and the app never rewrites .env. So at runtime, if a domain is set, we
|
|
* override config('app.url') to `https://<domain>` so that signed URLs, absolute
|
|
* links, password-reset mails, etc. resolve against the operator-configured host.
|
|
*
|
|
* Guarded hard: during `artisan migrate`, fresh installs, or any moment before the
|
|
* `settings` table exists (or the DB is unreachable), this must be a silent no-op so
|
|
* console commands and migrations never crash. Hence the Schema::hasTable() probe
|
|
* plus a defensive try/catch around the DB read.
|
|
*/
|
|
private function applyDashboardDomain(): void
|
|
{
|
|
try {
|
|
if (! Schema::hasTable('settings')) {
|
|
return;
|
|
}
|
|
|
|
$domain = Setting::get('dashboard_domain');
|
|
|
|
if ($domain === null || $domain === '') {
|
|
return;
|
|
}
|
|
|
|
config(['app.url' => 'https://'.$domain]);
|
|
} catch (Throwable) {
|
|
// No DB / table yet (install, migrate, CI). Leave config('app.url') as-is —
|
|
// never fail boot over a settings lookup.
|
|
}
|
|
}
|
|
}
|