45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Services\DummyDataService;
|
|
use Illuminate\Support\Facades\Auth;
|
|
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 untuk semua view (*)
|
|
View::composer('*', function ($view) {
|
|
if (Auth::check()) {
|
|
$user = Auth::user();
|
|
$notifikasi = collect(DummyDataService::getNotifikasiForUser($user));
|
|
$unreadCount = $notifikasi->where('read', false)->count();
|
|
$view->with('notifikasi', $notifikasi);
|
|
$view->with('unreadNotificationsCount', $unreadCount);
|
|
} else {
|
|
$view->with('notifikasi', collect([]));
|
|
$view->with('unreadNotificationsCount', 0);
|
|
}
|
|
});
|
|
}
|
|
}
|