simedkom/app/Providers/ViewServiceProvider.php

50 lines
1.5 KiB
PHP

<?php
namespace App\Providers;
use App\Models\Visitor;
use App\Settings\GeneralSettings;
use App\Settings\SeoSettings;
use App\Settings\SocialMediaSettings;
use Carbon\Carbon;
use Illuminate\Support\ServiceProvider;
class ViewServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}
/**
* Bootstrap services.
*/
public function boot(): void
{
view()->share('general', app(GeneralSettings::class));
view()->share('social', app(SocialMediaSettings::class));
view()->share('seo', app(SeoSettings::class));
view()->composer('components.partials.footer', function ($view) {
$routeStatisticModel = config('route-statistics.model', Visitor::class);
$today = $routeStatisticModel::whereDate('date', Carbon::today())->sum('counter');
$yesterday = $routeStatisticModel::whereDate('date', Carbon::yesterday())->sum('counter');
$thisMonth = $routeStatisticModel::whereMonth('date', Carbon::now()->month)
->whereYear('date', Carbon::now()->year)
->sum('counter');
$total = $routeStatisticModel::sum('counter');
$view->with('visitorStats', [
'today' => number_format($today),
'yesterday' => number_format($yesterday),
'thisMonth' => number_format($thisMonth),
'total' => number_format($total),
]);
});
}
}