2020-10-21 15:26:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2020-10-29 15:40:23 +01:00
|
|
|
use App\Models\Settings;
|
2023-11-23 17:31:28 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Support\Carbon;
|
2022-01-10 16:29:33 +01:00
|
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
|
use Illuminate\Support\Facades\URL;
|
2023-08-21 10:15:14 +00:00
|
|
|
use Illuminate\Support\Pluralizer;
|
2020-10-21 15:26:21 +02:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
2023-08-21 10:22:07 +02:00
|
|
|
/**
|
|
|
|
|
* Register any application services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function register()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 15:26:21 +02:00
|
|
|
/**
|
|
|
|
|
* Bootstrap any application services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function boot()
|
|
|
|
|
{
|
2023-11-23 17:31:28 +01:00
|
|
|
Model::shouldBeStrict(!$this->app->environment('production'));
|
|
|
|
|
|
|
|
|
|
// * HTTPS FIX
|
2022-05-02 14:30:59 +02:00
|
|
|
URL::forceScheme('https');
|
2022-08-11 10:03:16 +02:00
|
|
|
|
2022-01-10 16:29:33 +01:00
|
|
|
// * HA PROXY FIX.
|
|
|
|
|
App::singleton('clientIp', function () {
|
2023-08-21 10:22:07 +02:00
|
|
|
if (config('app.env') === 'local') {
|
2023-11-30 14:46:08 +01:00
|
|
|
return \IPLib\Factory::parseAddressString(request()->getClientIp());
|
2022-01-10 16:29:33 +01:00
|
|
|
} else {
|
2023-11-30 14:46:08 +01:00
|
|
|
return \IPLib\Factory::parseAddressString(
|
|
|
|
|
request()->server('HTTP_X_FORWARDED_FOR') ??
|
|
|
|
|
request()->getClientIp()
|
|
|
|
|
);
|
2022-01-10 16:29:33 +01:00
|
|
|
}
|
|
|
|
|
});
|
2023-08-21 10:22:07 +02:00
|
|
|
|
2023-11-23 17:31:28 +01:00
|
|
|
// * LOCAL FORCE eg: for Carbon
|
2022-01-10 16:29:33 +01:00
|
|
|
setlocale(LC_ALL, \sprintf(
|
|
|
|
|
'%s_%s.UTF-8',
|
|
|
|
|
config('app.locale'),
|
|
|
|
|
\strtoupper(config('app.locale'))
|
|
|
|
|
));
|
2023-11-23 17:31:28 +01:00
|
|
|
Carbon::setLocale(config('app.locale'));
|
2023-08-21 10:15:14 +00:00
|
|
|
Pluralizer::useLanguage('french');
|
|
|
|
|
|
2023-12-08 15:39:13 +01:00
|
|
|
// * Settings Provider
|
2022-01-07 19:00:30 +01:00
|
|
|
app()->singleton(Settings::class, function () {
|
2023-12-01 15:43:00 +01:00
|
|
|
if (!($settings = Settings::getCached()->first())) {
|
2022-01-07 19:00:30 +01:00
|
|
|
throw new \ErrorException('Settings not found in DB');
|
|
|
|
|
}
|
|
|
|
|
return $settings;
|
|
|
|
|
});
|
2020-10-21 15:26:21 +02:00
|
|
|
}
|
|
|
|
|
}
|