ldc-lionor/app/Providers/AppServiceProvider.php

67 lines
1.8 KiB
PHP
Raw Normal View History

2023-02-24 15:20:58 +00:00
<?php
namespace App\Providers;
2023-03-20 13:17:58 +00:00
use App\Models\Range;
2023-02-24 15:20:58 +00:00
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Carbon;
2023-03-20 13:17:58 +00:00
use Illuminate\Support\Facades\Schema;
2023-02-24 15:20:58 +00:00
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\URL;
2023-03-20 13:17:58 +00:00
use Illuminate\Support\Facades\View;
2023-02-24 15:20:58 +00:00
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
URL::forceScheme('https');
// * LOCAL FORCE eg: for Carbon
// * Remove numeric to prevent float seperator to breaking numeric transactions
\collect([\LC_TIME, \LC_MESSAGES, \LC_COLLATE, \LC_CTYPE, \LC_MONETARY])
->map(function ($contant) {
setlocale(
$contant,
\sprintf(
'%s_%s.UTF-8',
config('app.locale'),
\strtoupper(config('app.locale'))
)
);
});
Carbon::setLocale(config('app.locale'));
// * Force bootstrap paginator with tooltips.
2023-03-07 10:55:12 +00:00
Paginator::defaultView('modules.pagination');
2023-02-24 15:20:58 +00:00
// * HA PROXY FIX
app()->singleton('clientIp', function () {
if (config('app.env') === 'local') {
return request()->getClientIp();
}
return request()->server('HTTP_X_FORWARDED_FOR') ?? request()->getClientIp();
});
2023-03-20 13:17:58 +00:00
// * GAMMES
if (Schema::hasTable('ranges')) {
// On partage les ranges (gammes produit).
$ranges = Range::where('status', true)->get();
View::share('PublishedRangesGlobal', $ranges);
}
2023-02-24 15:20:58 +00:00
}
}