fix: ensure settings are only shared in views if the settings table exists

This commit is contained in:
Yoga Pangestu 2026-04-22 13:44:02 +07:00
parent c9998f5b4f
commit 09d70d052b

View File

@ -7,6 +7,7 @@
use App\Settings\SeoSettings;
use App\Settings\SocialMediaSettings;
use Carbon\Carbon;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class ViewServiceProvider extends ServiceProvider
@ -24,26 +25,28 @@ public function register(): void
*/
public function boot(): void
{
view()->share('general', app(GeneralSettings::class));
view()->share('social', app(SocialMediaSettings::class));
view()->share('seo', app(SeoSettings::class));
if (Schema::hasTable('settings')) {
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);
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');
$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),
]);
});
$view->with('visitorStats', [
'today' => number_format($today),
'yesterday' => number_format($yesterday),
'thisMonth' => number_format($thisMonth),
'total' => number_format($total),
]);
});
}
}
}