ldc-web/app/Providers/AppServiceProvider.php

71 lines
1.7 KiB
PHP
Raw Normal View History

2020-04-09 13:05:23 +02:00
<?php
namespace App\Providers;
2022-09-21 11:17:58 +00:00
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Carbon;
2023-09-22 09:59:11 +02:00
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\URL;
2020-04-09 13:05:23 +02:00
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
2023-09-22 09:59:11 +02:00
/**
* Register any application services.
*
* @return void
*/
public function register()
{
}
2020-04-09 13:05:23 +02:00
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2023-09-22 09:59:11 +02:00
// * HTTPS FIX
2022-04-27 17:29:10 +02:00
URL::forceScheme('https');
2022-09-21 11:17:58 +00:00
2023-09-22 09:59:11 +02:00
// * 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();
}
2022-09-21 11:17:58 +00:00
});
2023-09-22 09:59:11 +02:00
// * LOCAL FORCE eg: for Carbon
setlocale(LC_ALL, \sprintf(
'%s_%s.UTF-8',
config('app.locale'),
\strtoupper(config('app.locale'))
));
2022-09-21 11:17:58 +00:00
Carbon::setLocale(config('app.locale'));
2023-09-22 09:59:11 +02:00
$this->sharetoView();
}
2022-09-21 11:17:58 +00:00
2023-09-22 09:59:11 +02:00
/**
* Share Vars to view
*
* @return void
*/
private function sharetoView()
{
if (!app()->runningInConsole()) {
// * FORCE BOOTSTRAP PAGINATOR (or custom if in front)
// Early boot, request wont be filled as expected.
if (collect(explode('/', \request()->getPathInfo()))->get(1) === 'bo') {
Paginator::useBootstrap();
} else {
Paginator::useBootstrap();
2022-09-21 11:17:58 +00:00
}
2023-09-22 09:59:11 +02:00
}
2020-04-09 13:05:23 +02:00
}
}