ldc-legaulois/app/Providers/AppServiceProvider.php
2024-04-18 12:05:10 +02:00

53 lines
1.5 KiB
PHP

<?php
namespace App\Providers;
use App\Enums\Settings\SettingsType;
use App\Models\GeneralSetting;
use App\Models\MenuNodeData;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Model;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Model::shouldBeStrict(!$this->app->environment('production'));
// * HTTPS FIX
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'));
// * SETTINGS
App::singleton('settings', fn () => GeneralSetting::getCached());
// * Menu
App::singleton('menuNodeList', fn () => App::get('settings')
->where('type', SettingsType::mainMenu)->firstOrFail());
App::singleton('menuNodeDataList', fn () => MenuNodeData::getCached());
}
}