ldc-lionor/app/Providers/AppServiceProvider.php

87 lines
2.4 KiB
PHP
Raw Permalink Normal View History

2023-02-24 15:20:58 +00:00
<?php
namespace App\Providers;
use App\Enums\StaticPageType;
2023-03-20 13:17:58 +00:00
use App\Models\Range;
use App\Models\StaticPage;
2023-02-24 15:20:58 +00:00
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Carbon;
2023-08-28 08:46:47 +00:00
use Illuminate\Support\Facades\App;
2023-03-20 13:17:58 +00:00
use Illuminate\Support\Facades\Schema;
2023-02-24 15:20:58 +00:00
use Illuminate\Support\Facades\URL;
2023-03-20 13:17:58 +00:00
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
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()
{
2023-08-28 08:46:47 +00:00
// * HTTPS FIX
2023-02-24 15:20:58 +00:00
URL::forceScheme('https');
// * HA PROXY FIX
2023-08-28 08:46:47 +00:00
App::singleton('clientIp', function () {
2023-02-24 15:20:58 +00:00
if (config('app.env') === 'local') {
return request()->getClientIp();
2023-08-28 08:46:47 +00:00
} else {
return request()->server('HTTP_X_FORWARDED_FOR') ??
2024-09-06 08:30:55 +00:00
request()->getClientIp();
2023-02-24 15:20:58 +00:00
}
});
2023-03-20 13:17:58 +00:00
2023-08-28 08:46:47 +00:00
// * 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'));
$this->sharetoView();
}
/**
* Share Vars to view
*
* @return void
*/
private function sharetoView()
{
2023-06-23 10:06:05 +02:00
if (!app()->runningInConsole()) {
2023-08-28 08:46:47 +00:00
// * FORCE BOOTSTRAP PAGINATOR (or custom if in front)
// Early boot, request wont be filled as expected.
if (collect(explode('/', \request()->getPathInfo()))->get(1) === 'bo') {
Paginator::defaultView('modules.pagination');
} else {
Paginator::defaultView('modules.pagination');
}
2023-06-23 10:06:05 +02:00
// * GAMMES
if (Schema::hasTable('ranges')) {
// On partage les ranges (gammes produit).
2024-09-06 08:30:55 +00:00
$ranges = Range::query()->where('status', true)->get();
2023-06-23 10:06:05 +02:00
View::share('PublishedRangesGlobal', $ranges);
}
if (Schema::hasTable('static_pages')) {
$bannerSection = StaticPage::query()->where('type', StaticPageType::banner_section->value())->get();
View::share('bannerSection', $bannerSection);
}
2023-03-20 13:17:58 +00:00
}
2023-02-24 15:20:58 +00:00
}
}