update AppService provider

This commit is contained in:
Jérémy Munsch 2021-09-15 10:13:51 +02:00
parent 91bb88d26d
commit a135d8cae1

View file

@ -4,6 +4,8 @@ namespace App\Providers;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\URL;
@ -32,9 +34,33 @@ class AppServiceProvider extends ServiceProvider
//! Important pourra etre retiré quand la V1 sera supprimé
// empeche l'encapsulation dans data
JsonResource::withoutWrapping();
// LOCAL HTTPS FIX
if (!in_array(config('app.env'), ['local', 'testing'])) {
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'))
));
Carbon::setLocale(config('app.locale'));
// FORCE BOOTSTRAP PAGINATOR
if (!app()->runningInConsole()) {
Paginator::useBootstrap();
}
Paginator::useBootstrap();