ldc-legaulois/app/Providers/AppServiceProvider.php

54 lines
1.5 KiB
PHP
Raw Normal View History

2020-07-23 10:29:36 +02:00
<?php
namespace App\Providers;
use App\Enums\Settings\SettingsType;
use App\Models\GeneralSetting;
2024-04-18 12:05:10 +02:00
use App\Models\MenuNodeData;
2024-01-10 14:49:46 +01:00
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\App;
2021-03-21 22:51:19 +01:00
use Illuminate\Support\Facades\URL;
2020-07-23 10:29:36 +02:00
use Illuminate\Support\ServiceProvider;
2024-01-10 14:49:46 +01:00
use Illuminate\Database\Eloquent\Model;
2020-07-23 10:29:36 +02:00
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2024-01-10 14:49:46 +01:00
Model::shouldBeStrict(!$this->app->environment('production'));
// * HTTPS FIX
2023-01-10 09:21:53 +01:00
URL::forceScheme('https');
2024-01-10 14:49:46 +01:00
// * HA PROXY FIX
App::singleton('clientIp', function () {
if (config('app.env') === 'local') {
return request()->getClientIp();
} else {
return request()->server('HTTP_X_FORWARDED_FOR') ??
2024-01-10 14:49:46 +01:00
request()->getClientIp();
}
});
2024-01-10 14:49:46 +01:00
2022-04-01 11:40:12 +02:00
// * LOCAL FORCE eg: for Carbon
2024-01-10 14:49:46 +01:00
setlocale(LC_ALL, \sprintf(
'%s_%s.UTF-8',
config('app.locale'),
\strtoupper(config('app.locale'))
));
Carbon::setLocale(config('app.locale'));
// * SETTINGS
2024-04-18 12:05:10 +02:00
App::singleton('settings', fn () => GeneralSetting::getCached());
// * Menu
2024-04-18 12:05:10 +02:00
App::singleton('menuNodeList', fn () => App::get('settings')
->where('type', SettingsType::mainMenu)->firstOrFail());
App::singleton('menuNodeDataList', fn () => MenuNodeData::getCached());
2020-07-23 10:29:36 +02:00
}
}