diff --git a/app/Http/Controllers/Guru/DashboardController.php b/app/Http/Controllers/Guru/DashboardController.php new file mode 100644 index 0000000..84a76f9 --- /dev/null +++ b/app/Http/Controllers/Guru/DashboardController.php @@ -0,0 +1,36 @@ +user(); + + // Hitung total kelas yang diajar + $totalKelas = Mengajar::where('nip', $guru->nip) + ->distinct('id_kelas') + ->count('id_kelas'); + + // Hitung total mapel yang diajar + $totalMapel = Mengajar::where('nip', $guru->nip) + ->distinct('id_mapel') + ->count('id_mapel'); + + // Hitung total siswa yang diajar (lewat kelas) + $totalSiswa = Mengajar::where('nip', $guru->nip) + ->with('kelas.siswa') + ->get() + ->pluck('kelas.siswa') + ->flatten() + ->unique('nisn') + ->count(); + + return view('guru.dashboard', compact('totalKelas', 'totalMapel', 'totalSiswa')); + } +} diff --git a/app/Http/Controllers/Guru/GuruController.php b/app/Http/Controllers/Guru/GuruController.php new file mode 100644 index 0000000..658ba7d --- /dev/null +++ b/app/Http/Controllers/Guru/GuruController.php @@ -0,0 +1,29 @@ +has('search')) { + $search = $request->search; + $query->where('nama', 'like', "%$search%") + ->orWhere('nip', 'like', "%$search%"); + } + + // SHOW PER PAGE + $perPage = $request->get('perPage', 10); + + $gurus = $query->paginate($perPage)->appends($request->all()); + + return view('guru.guru.index', compact('gurus')); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Guru/KelasController.php b/app/Http/Controllers/Guru/KelasController.php new file mode 100644 index 0000000..a68308f --- /dev/null +++ b/app/Http/Controllers/Guru/KelasController.php @@ -0,0 +1,29 @@ +has('search')) { + $search = $request->search; + $query->where('nama_kelas', 'like', "%$search%") + ->orWhere('id_kelas', 'like', "%$search%"); + } + + // SHOW PER PAGE + $perPage = $request->get('perPage', 10); + + $kelass = $query->paginate($perPage)->appends($request->all()); + + return view('guru.kelas.index', compact('kelass')); + } +} diff --git a/app/Http/Controllers/Guru/LoginController.php b/app/Http/Controllers/Guru/LoginController.php new file mode 100644 index 0000000..858eb70 --- /dev/null +++ b/app/Http/Controllers/Guru/LoginController.php @@ -0,0 +1,48 @@ +validate([ + 'nip' => 'required', + 'password' => 'required', + ]); + + $credentials = $request->only('nip', 'password'); + + if (Auth::guard('guru')->attempt($credentials)) { + $request->session()->regenerate(); + + return redirect()->intended(route('guru.dashboard')); + } + + return back()->withErrors([ + 'nip' => 'NIP atau password salah' + ])->withInput($request->except('password')); + } + + public function logout(Request $request) + { + Auth::guard('guru')->logout(); + + $request->session()->invalidate(); + $request->session()->regenerateToken(); + + return redirect()->route('guru.login'); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Guru/ProfilController.php b/app/Http/Controllers/Guru/ProfilController.php new file mode 100644 index 0000000..b9ce187 --- /dev/null +++ b/app/Http/Controllers/Guru/ProfilController.php @@ -0,0 +1,42 @@ +user(); + return view('guru.profil.show', compact('guru')); + } + + public function update(Request $request) + { + $guru = Auth::guard('guru')->user(); + + $validated = $request->validate([ + 'nama' => 'required|string|max:100', + 'password' => 'nullable|string|min:6|confirmed', + ], [ + 'nama.required' => 'Nama wajib diisi', + 'password.min' => 'Password minimal 6 karakter', + 'password.confirmed' => 'Konfirmasi password tidak cocok', + ]); + + $guru->nama = $validated['nama']; + + if ($request->filled('password')) { + $guru->password = Hash::make($validated['password']); + } + + $guru->save(); + + return redirect()->route('guru.profil.show') + ->with('success', 'Profil berhasil diupdate!'); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Guru/SiswaController.php b/app/Http/Controllers/Guru/SiswaController.php new file mode 100644 index 0000000..f340636 --- /dev/null +++ b/app/Http/Controllers/Guru/SiswaController.php @@ -0,0 +1,38 @@ +has('search')) { + $search = $request->search; + $query->where('nama', 'like', "%$search%") + ->orWhere('nisn', 'like', "%$search%"); + } + + // FILTER BY KELAS + if ($request->has('filter_kelas') && $request->filter_kelas != '') { + $query->where('id_kelas', $request->filter_kelas); + } + + // SHOW PER PAGE + $perPage = $request->get('perPage', 10); + + $siswas = $query->paginate($perPage)->appends($request->all()); + + // Ambil semua kelas untuk dropdown filter + $kelass = Kelas::orderBy('tingkat')->orderBy('nama_kelas')->get(); + + return view('guru.siswa.index', compact('siswas', 'kelass')); + } +} \ No newline at end of file diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 2d7d726..3d13e1b 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -9,18 +9,21 @@ class Authenticate extends Middleware /** * Tentukan ke mana redirect jika user belum login. */ - protected function redirectTo($request): ?string - { - if (! $request->expectsJson()) { - // Cek guard admin dulu - if ($request->is('admin/*')) { - return route('admin.login'); - } - - // Default kalau bukan admin (misalnya guru/siswa) - return route('login'); + protected function redirectTo($request): ?string{ + if (! $request->expectsJson()) { + // Admin + if ($request->is('admin/*')) { + return route('admin.login'); } - return null; + // Guru + if ($request->is('guru/*')) { + return route('guru.login'); + } + + // Default + return route('login'); } -} + + return null; +}} diff --git a/app/Models/Guru.php b/app/Models/Guru.php index 1a94554..e6ffd1c 100644 --- a/app/Models/Guru.php +++ b/app/Models/Guru.php @@ -2,16 +2,16 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Database\Eloquent\Factories\HasFactory; -class Guru extends Model +class Guru extends Authenticatable { + use HasFactory; + protected $table = 'gurus'; - protected $primaryKey = 'nip'; - public $incrementing = false; - protected $keyType = 'string'; protected $fillable = [ @@ -23,4 +23,10 @@ class Guru extends Model protected $hidden = [ 'password', ]; + + // Relasi ke Mengajar + public function mengajars() + { + return $this->hasMany(Mengajar::class, 'nip', 'nip'); + } } \ No newline at end of file diff --git a/config/auth.php b/config/auth.php index 40c5a3f..12d1a8b 100644 --- a/config/auth.php +++ b/config/auth.php @@ -46,11 +46,11 @@ ], 'guru' => [ 'driver' => 'session', - 'provider' => 'guru', + 'provider' => 'gurus', ], 'siswa' => [ 'driver' => 'session', - 'provider' => 'siswa', + 'provider' => 'siswas', ], ], @@ -81,7 +81,7 @@ 'driver' => 'eloquent', 'model' => App\Models\Admin::class, ], - 'guru' => [ + 'gurus' => [ 'driver' => 'eloquent', 'model' => App\Models\Guru::class, ], diff --git a/resources/views/auth/landing-page.blade.php b/resources/views/auth/landing-page.blade.php index 8c1e9b5..1f7b688 100644 --- a/resources/views/auth/landing-page.blade.php +++ b/resources/views/auth/landing-page.blade.php @@ -7,5 +7,6 @@
Ini halaman landing sederhana. Silakan pilih login sesuai role kamu.
Login Admin + Login Guru @endsection diff --git a/resources/views/auth/login-guru.blade.php b/resources/views/auth/login-guru.blade.php index f00e041..23fa545 100644 --- a/resources/views/auth/login-guru.blade.php +++ b/resources/views/auth/login-guru.blade.php @@ -11,7 +11,7 @@ ← Kembali ke Landing Page -