ldc-showroom-bo/app/Providers/ViewServiceProvider.php
2025-05-28 17:20:29 +02:00

50 lines
1.5 KiB
PHP

<?php
namespace App\Providers;
use App\Models\Settings;
use App\Models\Tenant;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class ViewServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot(): void
{
$appInfos = Cache::remember('composer', 360, function () {
return json_decode(File::get(\app_path('../composer.json')));
});
// Share composer.json infos.
if (isset($appInfos->name) and isset($appInfos->version)) {
View::share('cpsr_name', $appInfos->name);
View::share('cpsr_version', $appInfos->version);
}
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') {
Paginator::defaultView('bo.modules.pagination');
} else {
Paginator::useBootstrapFive();
}
View::composer('*', function () {
View::share('settingsGlobal', Settings::getFromCache(tenant('id')));
});
if (Schema::hasTable('tenants')) {
View::share('tenantGlobal', Tenant::getFromCache());
}
} //end if
}
}