56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Settings;
|
|
use ErrorException;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Date;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Illuminate\Support\Pluralizer;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use IPLib\Factory;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
Model::shouldBeStrict(! $this->app->environment('production'));
|
|
|
|
// * HTTPS FIX
|
|
URL::forceScheme('https');
|
|
|
|
// * HA PROXY FIX.
|
|
App::singleton('clientIp', function () {
|
|
if (config('app.env') === 'local') {
|
|
return Factory::parseAddressString(request()->getClientIp());
|
|
}
|
|
|
|
return Factory::parseAddressString(
|
|
request()->server('HTTP_X_FORWARDED_FOR') ?? request()->getClientIp()
|
|
);
|
|
});
|
|
|
|
// * LOCAL FORCE eg: for Carbon
|
|
setlocale(LC_ALL, \sprintf(
|
|
'%s_%s.UTF-8',
|
|
config('app.locale'),
|
|
\strtoupper(config('app.locale'))
|
|
));
|
|
Date::setLocale(config('app.locale'));
|
|
Pluralizer::useLanguage('french');
|
|
|
|
// * Settings Provider
|
|
app()->singleton(Settings::class, function () {
|
|
throw_unless($settings = Settings::getCached()->first(), ErrorException::class, 'Settings not found in DB');
|
|
|
|
return $settings;
|
|
});
|
|
}
|
|
}
|