ldc-legaulois/app/Providers/AppServiceProvider.php

70 lines
1.8 KiB
PHP
Raw Normal View History

2020-07-23 10:29:36 +02:00
<?php
namespace App\Providers;
use App\Models\Articles;
2020-11-04 15:07:21 +01:00
use App\Models\Moments;
use Carbon\Carbon;
use Illuminate\Support\Facades\App;
2021-07-22 09:31:34 +02:00
use Illuminate\Support\Facades\Log;
2021-03-21 22:51:19 +01:00
use Illuminate\Support\Facades\URL;
2020-11-04 15:07:21 +01:00
use Illuminate\Support\Facades\View;
2020-07-23 10:29:36 +02:00
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()
{
// LOCAL HTTPS FIX
if (config('app.env') !== 'local') {
2021-03-21 22:51:19 +01:00
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'));
if (!app()->runningInConsole()) {
2021-07-22 09:31:34 +02:00
try {
View::share('momentFiche', Moments::getCachedStar() ?? false);
} catch (\Exception $e) {
Log::critical($e->getMessage());
View::share('momentFiche', false);
2021-07-22 10:23:33 +02:00
}
try {
View::share('actusGlobal', Articles::getCachedActus() ?? []);
} catch (\Exception $e) {
Log::critical($e->getMessage());
View::share('actusGlobal', []);
2021-07-22 09:31:34 +02:00
}
}
2020-07-23 10:29:36 +02:00
}
}