45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Models\Warga; // Pastikan model Warga sudah ada
|
|
|
|
class ViewServiceProvider extends ServiceProvider
|
|
{
|
|
public function boot(): void
|
|
{
|
|
// View Composer akan mengirimkan data ke layout/app (atau file layout utama kamu)
|
|
View::composer('layout.app', function ($view) {
|
|
if (Auth::check()) {
|
|
$user = Auth::user();
|
|
$notifCount = 0;
|
|
$notifData = collect();
|
|
$notifTitle = "";
|
|
|
|
if ($user->role == 'admin') {
|
|
// Admin melihat warga yang statusnya Ditolak dan butuh edit
|
|
$query = Warga::where('status_verifikasi', 'tolak');
|
|
$notifCount = $query->count();
|
|
$notifData = $query->latest()->take(5)->get();
|
|
$notifTitle = "Data Perlu Perbaikan";
|
|
} elseif ($user->role == 'verifikator') {
|
|
// Verifikator melihat warga yang masih Pending (perlu disetujui)
|
|
$query = Warga::where('status_verifikasi', 'pending');
|
|
$notifCount = $query->count();
|
|
$notifData = $query->latest()->take(5)->get();
|
|
$notifTitle = "Menunggu Persetujuan";
|
|
}
|
|
|
|
$view->with([
|
|
'notifCount' => $notifCount,
|
|
'notifData' => $notifData,
|
|
'notifTitle' => $notifTitle
|
|
]);
|
|
}
|
|
});
|
|
}
|
|
}
|