user(); try { $totalKelas = Mengajar::where('id_guru', $guru->id_guru) ->distinct('id_kelas') ->count('id_kelas'); $totalMapel = Mengajar::where('id_guru', $guru->id_guru) ->distinct('id_mapel') ->count('id_mapel'); $kelasIds = Mengajar::where('id_guru', $guru->id_guru) ->pluck('id_kelas') ->unique(); $totalSiswa = Siswa::whereIn('id_kelas', $kelasIds)->count(); } catch (\Exception $e) { $totalKelas = 0; $totalMapel = 0; $totalSiswa = 0; } return view('guru.dashboard', compact('totalKelas', 'totalMapel', 'totalSiswa')); } }