61 lines
2.1 KiB
PHP
61 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Prize;
|
|
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()
|
|
{
|
|
if (!app()->runningInConsole()) {
|
|
// * View shares
|
|
// ! Add view file pathes (also needed for console xml job).
|
|
View::addNamespace('back', resource_path('views'));
|
|
|
|
$appInfos = Cache::remember('composer', 84600, 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);
|
|
}
|
|
|
|
// * 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::useBootstrapFive();
|
|
}
|
|
|
|
if (Schema::hasTable('tenants')) {
|
|
View::share('tenantsGlobal', Tenant::setTenantsCached());
|
|
}
|
|
|
|
// Appliquer uniquement aux vues appelées après que le tenant ait été résolu.
|
|
View::composer('*', function ($view) {
|
|
if (tenant()) {
|
|
$view->with('settingsGlobal', Settings::query()
|
|
->where('tenant_id', \tenant()->getKey())
|
|
->firstOrFail());
|
|
$view->with('prizesGlobal', Prize::getCached());
|
|
}
|
|
});
|
|
} //end if
|
|
}
|
|
}
|