ldc-mesbr-app/app/Providers/AppServiceProvider.php

90 lines
2.3 KiB
PHP
Raw Normal View History

2023-09-13 16:48:17 +02:00
<?php
namespace App\Providers;
2023-11-24 20:26:29 +01:00
use DateTime;
use Illuminate\Database\Eloquent\Model;
2023-11-24 20:26:29 +01:00
use Illuminate\Support\Facades\Storage;
2023-09-13 16:48:17 +02:00
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
2023-11-24 20:26:29 +01:00
use Illuminate\Http\Resources\Json\JsonResource;
2023-09-13 16:48:17 +02:00
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Model::shouldBeStrict(!$this->app->environment('production'));
2023-09-13 16:48:17 +02:00
// * 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') ??
2023-11-24 16:03:46 +01:00
request()->getClientIp();
2023-09-13 16:48:17 +02: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();
2023-11-24 20:26:29 +01:00
JsonResource::withoutWrapping();
Storage::disk('coupons_pdf')->buildTemporaryUrlsUsing(
function (string $path, DateTime $expiration, array $options) {
return URL::temporarySignedRoute(
'pdf.stream',
$expiration,
array_merge($options, ['path' => $path])
);
}
);
2023-09-13 16:48:17 +02:00
}
/**
* Share Vars to view
*
* @return void
*/
private function sharetoView()
{
if (!app()->runningInConsole()) {
// * FORCE BOOTSTRAP PAGINATOR (or custom if in front)
// Early boot, request wont be filled as expected.
if (collect(explode('/', \request()->getPathInfo()))->get(1) === 'bo') {
2023-11-24 16:03:46 +01:00
Paginator::useBootstrapFive();
2023-09-13 16:48:17 +02:00
} else {
2023-11-24 16:03:46 +01:00
Paginator::useBootstrapFive();
2023-09-13 16:48:17 +02:00
}
}
}
}