ldc-nature-and-respect/app/Providers/ViewServiceProvider.php
2023-03-17 10:11:08 +01:00

41 lines
1.3 KiB
PHP

<?php
namespace App\Providers;
use App\Models\Home;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\File;
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()) {
// * 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::useBootstrap();
} else {
Paginator::defaultview('fo.partials.pagination');
}
}
$appInfos = Cache::remember('composer', 360, function () {
return json_decode(File::get(\app_path('../composer.json')));
});
// Share composer.json infos.
View::share('cpsr_name', $appInfos->name);
View::share('cpsr_version', $appInfos->version);
View::share('cpsr_license', $appInfos->license);
View::share('cpsr_time', now()->parse($appInfos->time)->isoFormat('Y'));
View::share('globalHome', Home::firstOrFail());
}
}