66 lines
2.3 KiB
PHP
66 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Setting;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class ConfigServiceProvider extends ServiceProvider
|
|
{
|
|
public function register(): void {}
|
|
|
|
public function boot(): void
|
|
{
|
|
if ($this->app->runningInConsole()) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$settings = Cache::rememberForever('system_settings', function () {
|
|
return Setting::all()->pluck('value', 'key')->toArray();
|
|
});
|
|
} catch (\Throwable $e) {
|
|
// DB not ready yet (e.g. first migration)
|
|
return;
|
|
}
|
|
|
|
if (empty($settings)) {
|
|
return;
|
|
}
|
|
|
|
if (!empty($settings['app_name'])) {
|
|
Config::set('app.name', $settings['app_name']);
|
|
}
|
|
|
|
if (!empty($settings['mail_host'])) {
|
|
Config::set([
|
|
'mail.mailers.smtp.host' => $settings['mail_host'],
|
|
'mail.mailers.smtp.port' => $settings['mail_port'] ?? '587',
|
|
'mail.mailers.smtp.username' => $settings['mail_username'] ?? '',
|
|
'mail.mailers.smtp.password' => $settings['mail_password'] ?? '',
|
|
'mail.mailers.smtp.encryption' => $settings['mail_encryption'] ?? 'tls',
|
|
'mail.from.address' => $settings['mail_from_address'] ?? 'hello@example.com',
|
|
'mail.from.name' => $settings['mail_from_name'] ?? ($settings['app_name'] ?? config('app.name')),
|
|
]);
|
|
}
|
|
|
|
if (!empty($settings['oauth_google_client_id'])) {
|
|
Config::set([
|
|
'services.google.client_id' => $settings['oauth_google_client_id'],
|
|
'services.google.client_secret' => $settings['oauth_google_client_secret'] ?? '',
|
|
'services.google.redirect' => url('/auth/google/callback'),
|
|
]);
|
|
}
|
|
|
|
if (!empty($settings['oauth_github_client_id'])) {
|
|
Config::set([
|
|
'services.github.client_id' => $settings['oauth_github_client_id'],
|
|
'services.github.client_secret' => $settings['oauth_github_client_secret'] ?? '',
|
|
'services.github.redirect' => url('/auth/github/callback'),
|
|
]);
|
|
}
|
|
}
|
|
}
|