lms/app/Providers/AppServiceProvider.php
Ahmed Darrazi 138cf3566b
All checks were successful
Build & Push Docker Image / docker (push) Successful in 1m50s
Fix mixed content by trusting proxy HTTPS
2025-12-18 15:35:51 +01:00

76 lines
2.3 KiB
PHP

<?php
namespace App\Providers;
use App\Models\Page;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\URL;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
$this->app->singleton('system_settings', function (): ?Setting {
try {
if (isDBConnected() && Schema::hasTable('settings')) {
return Setting::where('type', 'system')->first();
}
return null;
} catch (\Throwable $th) {
return null;
}
});
$this->app->singleton('intro_page', function (): ?Page {
try {
if (isDBConnected() && Schema::hasTable('settings')) {
$home = Setting::where('type', 'home_page')->first();
$page = Page::where('id', $home->fields['page_id'])
->with(['sections' => function ($query) {
$query->orderBy('sort', 'asc');
}])
->first();
return $page;
}
return null;
} catch (\Throwable $th) {
return null;
}
});
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Schema::defaultStringLength(191);
// Fix for shared hosting missing CURL_SSLVERSION_TLSv1_2 constant
if (!defined('CURL_SSLVERSION_TLSv1_2')) {
define('CURL_SSLVERSION_TLSv1_2', 6); // 6 = TLSv1.2
}
ResetPassword::createUrlUsing(function (User $user, string $token) {
return env('FRONTEND_URL') . '/reset-password?token=' . $token . '&email=' . $user->email;
});
// Force HTTPS URLs in non-local envs to avoid mixed-content issues when TLS is terminated
// in front of the app container (e.g. Dokploy/Traefik).
if (!$this->app->runningInConsole() && !$this->app->environment('local')) {
URL::forceScheme('https');
}
}
}