54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Settings;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
URL::forceScheme('https');
|
|
|
|
// * HA PROXY FIX.
|
|
App::singleton('clientIp', function () {
|
|
if (config('app.env') === 'local') {
|
|
return request()->getClientIp();
|
|
} else {
|
|
return 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'))
|
|
));
|
|
|
|
app()->singleton(Settings::class, function () {
|
|
if (!($settings = Settings::find(1))) {
|
|
throw new \ErrorException('Settings not found in DB');
|
|
}
|
|
return $settings;
|
|
});
|
|
}
|
|
}
|