TIF_NGANJUK_E41220778/app/Providers/AppServiceProvider.php

44 lines
1.1 KiB
PHP

<?php
namespace App\Providers;
use App\Services\DummyDataService;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
if ($this->app->environment('production')) {
URL::forceScheme('https');
}
View::composer('*', function ($view) {
$notifikasi = collect([]);
$unreadNotificationsCount = 0;
// Hanya ambil notifikasi jika ada pengguna yang login
if (auth()->check()) {
$user = auth()->user();
$notifikasi = collect(DummyDataService::getNotifikasiForUser($user));
$unreadNotificationsCount = $notifikasi->where('read', false)->count();
}
$view->with(compact('notifikasi', 'unreadNotificationsCount'));
});
}
}