76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Actu;
|
|
use App\Models\Articles;
|
|
use App\Models\Moments;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Illuminate\Support\Facades\View;
|
|
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') {
|
|
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()) {
|
|
try {
|
|
View::share('momentFiche', Moments::getCachedStar() ?? false);
|
|
} catch (\Exception $e) {
|
|
Log::critical($e->getMessage());
|
|
View::share('momentFiche', false);
|
|
}
|
|
try {
|
|
View::share('ActusGlobal', Actu::getCachedActus() ?? []);
|
|
} catch (\Exception $e) {
|
|
Log::critical($e->getMessage());
|
|
View::share('ActusGlobal', []);
|
|
}
|
|
try {
|
|
View::share('ArticlesGlobal', Articles::getCachedArticles() ?? []);
|
|
} catch (\Exception $e) {
|
|
Log::critical($e->getMessage());
|
|
View::share('ArticlesGlobal', []);
|
|
}
|
|
}
|
|
}
|
|
}
|