Refactor: form tambah pengguna & penyesuaian struktur tabel users
This commit is contained in:
parent
c1e631c3ce
commit
692ee5009b
|
|
@ -3,16 +3,16 @@
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\User; // Model User Asli
|
use App\Models\User;
|
||||||
use App\Models\MasterInduk; // Model Whitelist
|
use App\Models\MasterInduk;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$users = User::orderBy('created_at', 'desc')->paginate(10);
|
$users = User::orderBy('created_at', 'desc')->paginate(10);
|
||||||
|
|
||||||
$whitelists = MasterInduk::orderBy('created_at', 'desc')->get();
|
$whitelists = MasterInduk::orderBy('created_at', 'desc')->get();
|
||||||
|
|
||||||
return view('admin.pengguna.index', [
|
return view('admin.pengguna.index', [
|
||||||
|
|
@ -27,6 +27,63 @@ public function create()
|
||||||
return view('admin.pengguna.create', ['pageTitle' => 'Tambah Pengguna Baru']);
|
return view('admin.pengguna.create', ['pageTitle' => 'Tambah Pengguna Baru']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'nama_lengkap' => 'required|string|max:255',
|
||||||
|
'email' => 'required|email|unique:users,email',
|
||||||
|
'role' => 'required|in:siswa,guru,penjaga perpus',
|
||||||
|
'no_hp' => 'nullable|string|max:20',
|
||||||
|
'password' => 'required|min:6|confirmed',
|
||||||
|
'nomor_induk' => [
|
||||||
|
'required',
|
||||||
|
function ($attribute, $value, $fail) use ($request) {
|
||||||
|
$label = $request->role == 'siswa' ? 'NISN' : 'NIP/NIK';
|
||||||
|
|
||||||
|
// Cek Nisn/Nip sudah dipakai di tabel users
|
||||||
|
$sudahDipakai = User::where('nisn', $value)->orWhere('nip', $value)->exists();
|
||||||
|
if ($sudahDipakai) {
|
||||||
|
$fail("{$label} ini sudah digunakan oleh akun lain.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($request->role, ['siswa', 'guru'])) {
|
||||||
|
$terdaftar = MasterInduk::where('nomor_induk', $value)
|
||||||
|
->where('role', $request->role)
|
||||||
|
->exists();
|
||||||
|
if (!$terdaftar) {
|
||||||
|
$fail("{$label} tidak terdaftar di data sekolah. Hubungi admin.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
], [
|
||||||
|
'role.in' => 'Pilih role yang valid.',
|
||||||
|
'email.unique' => 'Email sudah terdaftar.',
|
||||||
|
'password.confirmed' => 'Konfirmasi password tidak cocok.'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user = new User();
|
||||||
|
$user->name = $request->nama_lengkap;
|
||||||
|
$user->email = $request->email;
|
||||||
|
$user->role = $request->role;
|
||||||
|
$user->password = Hash::make($request->password);
|
||||||
|
$user->no_hp = $request->no_hp;
|
||||||
|
|
||||||
|
// Validasi NISN dan NIP berdasarkan Role
|
||||||
|
if ($request->role == 'siswa') {
|
||||||
|
$user->nisn = $request->nomor_induk;
|
||||||
|
$user->kelas = $request->kelas;
|
||||||
|
$user->golongan = $request->golongan;
|
||||||
|
} else {
|
||||||
|
$user->nip = $request->nomor_induk;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
return redirect()->route('admin.pengguna.index')->with('success', 'Pengguna berhasil ditambahkan.');
|
||||||
|
}
|
||||||
|
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
$pengguna = User::findOrFail($id);
|
$pengguna = User::findOrFail($id);
|
||||||
|
|
@ -36,6 +93,71 @@ public function edit($id)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function update(Request $request, $id)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'nama_lengkap' => 'required|string|max:255',
|
||||||
|
'email' => 'required|email|unique:users,email,' . $id,
|
||||||
|
'role' => 'required|in:siswa,guru,penjaga perpus',
|
||||||
|
'no_hp' => 'nullable|string|max:20',
|
||||||
|
'password' => 'nullable|min:6|confirmed',
|
||||||
|
'nomor_induk' => [
|
||||||
|
'required',
|
||||||
|
function ($attribute, $value, $fail) use ($request, $id) {
|
||||||
|
$label = $request->role == 'siswa' ? 'NISN' : 'NIP/NIK';
|
||||||
|
|
||||||
|
// cek nisn/nip sudah dipakai di tabel users (kecuali oleh dirinya sendiri)
|
||||||
|
$sudahDipakai = User::where(function ($query) use ($value) {
|
||||||
|
$query->where('nisn', $value)->orWhere('nip', $value);
|
||||||
|
})->where('id', '!=', $id)->exists();
|
||||||
|
|
||||||
|
if ($sudahDipakai) {
|
||||||
|
$fail("{$label} ini sudah digunakan oleh akun lain.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($request->role, ['siswa', 'guru'])) {
|
||||||
|
$terdaftar = MasterInduk::where('nomor_induk', $value)
|
||||||
|
->where('role', $request->role)
|
||||||
|
->exists();
|
||||||
|
if (!$terdaftar) {
|
||||||
|
$fail("{$label} tidak terdaftar di data sekolah. Hubungi admin.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user = User::findOrFail($id);
|
||||||
|
$user->name = $request->nama_lengkap;
|
||||||
|
$user->email = $request->email;
|
||||||
|
$user->role = $request->role;
|
||||||
|
$user->no_hp = $request->no_hp;
|
||||||
|
|
||||||
|
// Jika password diisi, maka update. Jika kosong, biarkan password lama.
|
||||||
|
if ($request->filled('password')) {
|
||||||
|
$user->password = \Illuminate\Support\Facades\Hash::make($request->password);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->nisn = null;
|
||||||
|
$user->nip = null;
|
||||||
|
$user->kelas = null;
|
||||||
|
$user->golongan = null;
|
||||||
|
|
||||||
|
// Masukkan kembali sesuai role
|
||||||
|
if ($request->role == 'siswa') {
|
||||||
|
$user->nisn = $request->nomor_induk;
|
||||||
|
$user->kelas = $request->kelas;
|
||||||
|
$user->golongan = $request->golongan;
|
||||||
|
} else {
|
||||||
|
$user->nip = $request->nomor_induk;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
return redirect()->route('admin.pengguna.index')->with('success', 'Data pengguna berhasil diperbarui.');
|
||||||
|
}
|
||||||
|
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
User::findOrFail($id)->delete();
|
User::findOrFail($id)->delete();
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@ public function up(): void
|
||||||
$table->string('role')->default('siswa');
|
$table->string('role')->default('siswa');
|
||||||
$table->string('nisn')->nullable();
|
$table->string('nisn')->nullable();
|
||||||
$table->string('nip')->nullable();
|
$table->string('nip')->nullable();
|
||||||
$table->string('nomor_hp')->nullable();
|
$table->string('no_hp')->nullable();
|
||||||
|
$table->string('golongan')->nullable();
|
||||||
$table->string('kelas')->nullable();
|
$table->string('kelas')->nullable();
|
||||||
$table->rememberToken();
|
$table->rememberToken();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ public function run()
|
||||||
MasterInduk::truncate();
|
MasterInduk::truncate();
|
||||||
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
|
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
|
||||||
|
|
||||||
// 1. ISI DATA INDUK (WHITELIST)
|
|
||||||
$whitelist = [
|
$whitelist = [
|
||||||
['nomor_induk' => '1234567890', 'role' => 'siswa', 'nama_pemilik' => 'Silvi Rahmawati'],
|
['nomor_induk' => '1234567890', 'role' => 'siswa', 'nama_pemilik' => 'Silvi Rahmawati'],
|
||||||
['nomor_induk' => '9988776655', 'role' => 'siswa', 'nama_pemilik' => 'Siti Nurhaliza'],
|
['nomor_induk' => '9988776655', 'role' => 'siswa', 'nama_pemilik' => 'Siti Nurhaliza'],
|
||||||
|
|
@ -30,18 +29,19 @@ public function run()
|
||||||
MasterInduk::create($w);
|
MasterInduk::create($w);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. ISI USER ASLI (ID USER DISAMAKAN DENGAN DUMMY)
|
// ISI USER ASLI
|
||||||
|
|
||||||
// ID 1: Silvi (Siswa)
|
// ID 1: Silvi (Siswa)
|
||||||
User::create([
|
User::create([
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'name' => 'Silvi Rahmawati', // Pakai 'name' saja, 'nama_lengkap' dihapus
|
'name' => 'Silvi Rahmawati',
|
||||||
'email' => 'silvi.rahmawati@smkn1perpus.sch.id',
|
'email' => 'silvi.rahmawati@smkn1perpus.sch.id',
|
||||||
'password' => Hash::make('password'),
|
'password' => Hash::make('password'),
|
||||||
'role' => 'siswa',
|
'role' => 'siswa',
|
||||||
'nisn' => '1234567890',
|
'nisn' => '1234567890',
|
||||||
'nomor_hp' => '08123456789',
|
'no_hp' => '08123456789',
|
||||||
'kelas' => 'XII RPL'
|
'kelas' => 'XII RPL',
|
||||||
|
'golongan' => 'A'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// ID 2: Budi (Admin/Penjaga)
|
// ID 2: Budi (Admin/Penjaga)
|
||||||
|
|
@ -62,8 +62,9 @@ public function run()
|
||||||
'password' => Hash::make('password'),
|
'password' => Hash::make('password'),
|
||||||
'role' => 'siswa',
|
'role' => 'siswa',
|
||||||
'nisn' => '9988776655',
|
'nisn' => '9988776655',
|
||||||
'nomor_hp' => '081998877665',
|
'no_hp' => '081998877665',
|
||||||
'kelas' => 'XII RPL A'
|
'kelas' => 'XII RPL',
|
||||||
|
'golongan' => 'B'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// ID 4: Andi (Siswa)
|
// ID 4: Andi (Siswa)
|
||||||
|
|
@ -74,8 +75,9 @@ public function run()
|
||||||
'password' => Hash::make('password'),
|
'password' => Hash::make('password'),
|
||||||
'role' => 'siswa',
|
'role' => 'siswa',
|
||||||
'nisn' => '5566778899',
|
'nisn' => '5566778899',
|
||||||
'nomor_hp' => '081556677889',
|
'no_hp' => '081556677889',
|
||||||
'kelas' => 'XII RPL A'
|
'kelas' => 'XII RPL',
|
||||||
|
'golongan' => 'C'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// ID 5: Rina (Guru)
|
// ID 5: Rina (Guru)
|
||||||
|
|
|
||||||
|
|
@ -11,48 +11,171 @@
|
||||||
<div class="col-md-10">
|
<div class="col-md-10">
|
||||||
<div class="card border-0 shadow-sm">
|
<div class="card border-0 shadow-sm">
|
||||||
<div class="card-body p-4">
|
<div class="card-body p-4">
|
||||||
<div class="card-body">
|
<form action="{{ route('admin.pengguna.store') }}" method="POST">
|
||||||
<form action="#" method="POST">
|
@csrf
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="role" class="form-label">Role <span class="text-danger">*</span></label>
|
||||||
|
<select class="form-select @error('role') is-invalid @enderror" id="role"
|
||||||
|
name="role" required onchange="toggleFields()">
|
||||||
|
<option value="" selected disabled>Pilih role terlebih dahulu...</option>
|
||||||
|
<option value="siswa" {{ old('role') == 'siswa' ? 'selected' : '' }}>Siswa</option>
|
||||||
|
<option value="guru" {{ old('role') == 'guru' ? 'selected' : '' }}>Guru</option>
|
||||||
|
<option value="penjaga perpus" {{ old('role') == 'penjaga perpus' ? 'selected' : '' }}>
|
||||||
|
Penjaga Perpustakaan</option>
|
||||||
|
</select>
|
||||||
|
@error('role')
|
||||||
|
<div class="invalid-feedback">{{ $message }}</div>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- Bagian Form Dinamis --}}
|
||||||
|
<div id="dynamic-form" class="d-none">
|
||||||
|
|
||||||
|
{{-- Nama Lengkap --}}
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="nama_lengkap" class="form-label">Nama Lengkap</label>
|
<label for="nama_lengkap" class="form-label">Nama Lengkap</label>
|
||||||
<input type="text" class="form-control" id="nama_lengkap"
|
<input type="text" class="form-control @error('nama_lengkap') is-invalid @enderror"
|
||||||
placeholder="Masukkan nama lengkap">
|
id="nama_lengkap" name="nama_lengkap" value="{{ old('nama_lengkap') }}" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{-- Identitas Unik (NISN/NIP) --}}
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="email" class="form-label">Email</label>
|
<label for="nomor_induk" class="form-label" id="label_nomor_induk">NISN / NIP</label>
|
||||||
<input type="email" class="form-control" id="email"
|
<input type="number" class="form-control @error('nomor_induk') is-invalid @enderror"
|
||||||
placeholder="Masukkan alamat email">
|
id="nomor_induk" name="nomor_induk" value="{{ old('nomor_induk') }}"
|
||||||
</div>
|
placeholder="Masukkan Nomor Induk">
|
||||||
<div class="mb-3">
|
@error('nomor_induk')
|
||||||
<label for="nisn" class="form-label">NISN (jika siswa)</label>
|
<div class="invalid-feedback">{{ $message }}</div>
|
||||||
<input type="text" class="form-control" id="nisn" placeholder="Masukkan NISN">
|
@enderror
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="role" class="form-label">Role</label>
|
|
||||||
<select class="form-select" id="role">
|
|
||||||
<option selected>Pilih role...</option>
|
|
||||||
<option value="siswa">Siswa</option>
|
|
||||||
<option value="penjaga perpus">Penjaga Perpus</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{-- Kontak (Email & HP) --}}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 mb-3">
|
<div class="col-md-6 mb-3">
|
||||||
<label for="password" class="form-label">Password</label>
|
<label for="email" class="form-label">Email</label>
|
||||||
<input type="password" class="form-control" id="password">
|
<input type="email" class="form-control @error('email') is-invalid @enderror"
|
||||||
|
id="email" name="email" value="{{ old('email') }}" required>
|
||||||
|
@error('email')
|
||||||
|
<div class="invalid-feedback">{{ $message }}</div>
|
||||||
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 mb-3">
|
<div class="col-md-6 mb-3">
|
||||||
<label for="password_confirmation" class="form-label">Konfirmasi Password</label>
|
<label for="no_hp" class="form-label">No. Handphone</label>
|
||||||
<input type="password" class="form-control" id="password_confirmation">
|
<input type="text" class="form-control" id="no_hp" name="no_hp"
|
||||||
|
value="{{ old('no_hp') }}" placeholder="Contoh: 08123456789">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{-- Field Khusus Siswa (Kelas & Golongan) --}}
|
||||||
|
<div class="row" id="field_siswa_only" style="display: none;">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="kelas" class="form-label">Kelas</label>
|
||||||
|
<input type="text" class="form-control" id="kelas" name="kelas"
|
||||||
|
value="{{ old('kelas') }}" placeholder="Contoh: XII RPL 1">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="golongan" class="form-label">Golongan</label>
|
||||||
|
<input type="text" class="form-control" id="golongan" name="golongan"
|
||||||
|
value="{{ old('golongan') }}" placeholder="Contoh: A/B">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<div class="d-flex justify-content-end">
|
|
||||||
<button type="submit" class="btn btn-primary">Simpan Pengguna</button>
|
{{-- Keamanan (Password) --}}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="password" class="form-label">
|
||||||
|
Password
|
||||||
|
</label>
|
||||||
|
<div class="input-group has-validation">
|
||||||
|
<input type="password"
|
||||||
|
class="form-control @error('password') is-invalid @enderror" id="password"
|
||||||
|
name="password">
|
||||||
|
<button class="btn btn-outline-secondary toggle-password" type="button"
|
||||||
|
data-target="password">
|
||||||
|
<i class="bi bi-eye" id="icon-password"></i>
|
||||||
|
</button>
|
||||||
|
@error('password')
|
||||||
|
<div class="invalid-feedback">{{ $message }}</div>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="password_confirmation" class="form-label">Konfirmasi Password</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="password" class="form-control" id="password_confirmation"
|
||||||
|
name="password_confirmation">
|
||||||
|
<button class="btn btn-outline-secondary toggle-password" type="button"
|
||||||
|
data-target="password_confirmation">
|
||||||
|
<i class="bi bi-eye" id="icon-password_confirmation"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-end mt-3">
|
||||||
|
<button type="submit" class="btn btn-primary px-4">Simpan Pengguna</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
<script>
|
||||||
|
function toggleFields() {
|
||||||
|
const role = document.getElementById('role').value;
|
||||||
|
const dynamicForm = document.getElementById('dynamic-form');
|
||||||
|
const labelInduk = document.getElementById('label_nomor_induk');
|
||||||
|
const inputInduk = document.getElementById('nomor_induk');
|
||||||
|
|
||||||
|
const fieldSiswaOnly = document.getElementById('field_siswa_only');
|
||||||
|
|
||||||
|
// Tampilkan form
|
||||||
|
if (role) {
|
||||||
|
dynamicForm.classList.remove('d-none');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Atur Label & Field berdasarkan Role
|
||||||
|
if (role === 'siswa') {
|
||||||
|
labelInduk.innerHTML = 'NISN <span class="text-danger">*</span>';
|
||||||
|
inputInduk.placeholder = 'Masukkan NISN Siswa';
|
||||||
|
fieldSiswaOnly.style.display = 'flex';
|
||||||
|
} else if (role === 'guru') {
|
||||||
|
labelInduk.innerHTML = 'NIP / NIK <span class="text-danger">*</span>';
|
||||||
|
inputInduk.placeholder = 'Masukkan NIP/NIK Guru';
|
||||||
|
fieldSiswaOnly.style.display = 'none';
|
||||||
|
} else if (role === 'penjaga perpus') {
|
||||||
|
labelInduk.innerHTML = 'NIP / NIK <span class="text-danger">*</span>';
|
||||||
|
inputInduk.placeholder = 'Masukkan NIP/NIK Petugas';
|
||||||
|
fieldSiswaOnly.style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
toggleFields();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll('.toggle-password').forEach(function(button) {
|
||||||
|
button.addEventListener('click', function() {
|
||||||
|
const targetId = this.getAttribute('data-target');
|
||||||
|
const input = document.getElementById(targetId);
|
||||||
|
const icon = document.getElementById('icon-' + targetId);
|
||||||
|
|
||||||
|
if (input.type === 'password') {
|
||||||
|
input.type = 'text';
|
||||||
|
icon.classList.remove('bi-eye');
|
||||||
|
icon.classList.add('bi-eye-slash');
|
||||||
|
} else {
|
||||||
|
input.type = 'password';
|
||||||
|
icon.classList.remove('bi-eye-slash');
|
||||||
|
icon.classList.add('bi-eye');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</x-app-layout>
|
</x-app-layout>
|
||||||
|
|
|
||||||
|
|
@ -11,52 +11,117 @@
|
||||||
<div class="col-md-10">
|
<div class="col-md-10">
|
||||||
<div class="card border-0 shadow-sm">
|
<div class="card border-0 shadow-sm">
|
||||||
<div class="card-body p-4">
|
<div class="card-body p-4">
|
||||||
<div class="card-body">
|
<form action="{{ route('admin.pengguna.update', $pengguna->id) }}" method="POST">
|
||||||
<form action="#" method="POST">
|
@csrf
|
||||||
|
@method('PUT')
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="role" class="form-label">Role <span class="text-danger">*</span></label>
|
||||||
|
<select class="form-select @error('role') is-invalid @enderror" id="role" name="role" required onchange="toggleFields()">
|
||||||
|
<option value="siswa" {{ old('role', $pengguna->role) == 'siswa' ? 'selected' : '' }}>Siswa</option>
|
||||||
|
<option value="guru" {{ old('role', $pengguna->role) == 'guru' ? 'selected' : '' }}>Guru</option>
|
||||||
|
<option value="penjaga perpus" {{ old('role', $pengguna->role) == 'penjaga perpus' ? 'selected' : '' }}>Penjaga Perpustakaan</option>
|
||||||
|
</select>
|
||||||
|
@error('role') <div class="invalid-feedback">{{ $message }}</div> @enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{-- Bagian Form Dinamis --}}
|
||||||
|
<div id="dynamic-form">
|
||||||
|
|
||||||
|
{{-- Nama Lengkap --}}
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="nama_lengkap" class="form-label">Nama Lengkap</label>
|
<label for="nama_lengkap" class="form-label">Nama Lengkap</label>
|
||||||
<input type="text" class="form-control" id="nama_lengkap"
|
<input type="text" class="form-control @error('nama_lengkap') is-invalid @enderror"
|
||||||
value="{{ $pengguna['nama_lengkap'] }}">
|
id="nama_lengkap" name="nama_lengkap" value="{{ old('nama_lengkap', $pengguna->name) }}" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{-- Identitas Unik (NISN/NIP) --}}
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="email" class="form-label">Email</label>
|
@php
|
||||||
<input type="email" class="form-control" id="email"
|
$oldNomorInduk = old('nomor_induk', $pengguna->role == 'siswa' ? $pengguna->nisn : $pengguna->nip);
|
||||||
value="{{ $pengguna['email'] }}">
|
@endphp
|
||||||
</div>
|
<label for="nomor_induk" class="form-label" id="label_nomor_induk">NISN / NIP</label>
|
||||||
<div class="mb-3">
|
<input type="number" class="form-control @error('nomor_induk') is-invalid @enderror"
|
||||||
<label for="nisn" class="form-label">NISN (jika siswa)</label>
|
id="nomor_induk" name="nomor_induk" value="{{ $oldNomorInduk }}" placeholder="Masukkan Nomor Induk">
|
||||||
<input type="text" class="form-control" id="nisn"
|
@error('nomor_induk') <div class="invalid-feedback fw-bold">{{ $message }}</div> @enderror
|
||||||
value="{{ $pengguna['nisn'] ?? '' }}">
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="role" class="form-label">Role</label>
|
|
||||||
<select class="form-select" id="role">
|
|
||||||
<option>Pilih role...</option>
|
|
||||||
<option value="siswa" @if ($pengguna['role'] == 'siswa') selected @endif>Siswa
|
|
||||||
</option>
|
|
||||||
<option value="penjaga perpus" @if ($pengguna['role'] == 'penjaga perpus') selected @endif>
|
|
||||||
Penjaga Perpus</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{-- Kontak (Email & HP) --}}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 mb-3">
|
<div class="col-md-6 mb-3">
|
||||||
<label for="password" class="form-label">Password Baru</label>
|
<label for="email" class="form-label">Email</label>
|
||||||
<input type="password" class="form-control" id="password"
|
<input type="email" class="form-control @error('email') is-invalid @enderror"
|
||||||
placeholder="Kosongkan jika tidak diubah">
|
id="email" name="email" value="{{ old('email', $pengguna->email) }}" required>
|
||||||
|
@error('email') <div class="invalid-feedback">{{ $message }}</div> @enderror
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 mb-3">
|
<div class="col-md-6 mb-3">
|
||||||
<label for="password_confirmation" class="form-label">Konfirmasi Password</label>
|
<label for="no_hp" class="form-label">No. Handphone</label>
|
||||||
<input type="password" class="form-control" id="password_confirmation">
|
<input type="text" class="form-control" id="no_hp" name="no_hp" value="{{ old('no_hp', $pengguna->no_hp) }}" placeholder="Contoh: 08123456789">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{-- Field Khusus Siswa (Kelas & Golongan) --}}
|
||||||
|
<div class="row" id="field_siswa_only" style="display: none;">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="kelas" class="form-label">Kelas</label>
|
||||||
|
<input type="text" class="form-control" id="kelas" name="kelas" value="{{ old('kelas', $pengguna->kelas) }}" placeholder="Contoh: XII RPL 1">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="golongan" class="form-label">Golongan</label>
|
||||||
|
<input type="text" class="form-control" id="golongan" name="golongan" value="{{ old('golongan', $pengguna->golongan) }}" placeholder="Contoh: A/B">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<div class="d-flex justify-content-end">
|
|
||||||
<button type="submit" class="btn btn-primary">Simpan Perubahan</button>
|
{{-- Keamanan (Password) --}}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="password" class="form-label">Password Baru <span class="small text-muted">(opsional)</span></label>
|
||||||
|
<input type="password" class="form-control @error('password') is-invalid @enderror" id="password" name="password" placeholder="Kosongkan jika tidak diubah">
|
||||||
|
@error('password') <div class="invalid-feedback">{{ $message }}</div> @enderror
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="password_confirmation" class="form-label">Konfirmasi Password Baru</label>
|
||||||
|
<input type="password" class="form-control" id="password_confirmation" name="password_confirmation" placeholder="Ulangi password baru">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-end mt-3">
|
||||||
|
<button type="submit" class="btn btn-primary px-4">Simpan Perubahan</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
<script>
|
||||||
|
function toggleFields() {
|
||||||
|
const role = document.getElementById('role').value;
|
||||||
|
const labelInduk = document.getElementById('label_nomor_induk');
|
||||||
|
const inputInduk = document.getElementById('nomor_induk');
|
||||||
|
const fieldSiswaOnly = document.getElementById('field_siswa_only');
|
||||||
|
|
||||||
|
// Atur Label & Field berdasarkan Role
|
||||||
|
if (role === 'siswa') {
|
||||||
|
labelInduk.innerHTML = 'NISN <span class="text-danger">*</span>';
|
||||||
|
inputInduk.placeholder = 'Masukkan NISN Siswa';
|
||||||
|
fieldSiswaOnly.style.display = 'flex';
|
||||||
|
} else if (role === 'guru') {
|
||||||
|
labelInduk.innerHTML = 'NIP / NIK <span class="text-danger">*</span>';
|
||||||
|
inputInduk.placeholder = 'Masukkan NIP/NIK Guru';
|
||||||
|
fieldSiswaOnly.style.display = 'none';
|
||||||
|
} else if (role === 'penjaga perpus') {
|
||||||
|
labelInduk.innerHTML = 'NIP / NIK <span class="text-danger">*</span>';
|
||||||
|
inputInduk.placeholder = 'Masukkan NIP/NIK Petugas';
|
||||||
|
fieldSiswaOnly.style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
toggleFields();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</x-app-layout>
|
</x-app-layout>
|
||||||
|
|
@ -7,41 +7,61 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card shadow mb-5">
|
<div class="card shadow mb-5">
|
||||||
<div class="card-header py-3">
|
<div class="card-header py-3 d-flex justify-content-between align-items-center">
|
||||||
<h6 class="m-0 font-weight-bold text-primary">Daftar Pengguna Aktif</h6>
|
<h6 class="m-0 font-weight-bold text-primary">Daftar Pengguna Aktif</h6>
|
||||||
|
<a href="{{ route('admin.pengguna.create') }}" class="btn btn-primary">
|
||||||
|
<i class="bi bi-plus-circle-fill me-2"></i>Tambah Pengguna
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-bordered" width="100%" cellspacing="0">
|
<table class="table table-bordered align-middle" width="100%" cellspacing="0">
|
||||||
<thead>
|
<thead class="table-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th>No</th>
|
<th>No</th>
|
||||||
<th>Nama Lengkap</th>
|
<th>Nama Lengkap</th>
|
||||||
<th>Email</th>
|
<th>Kontak (Email & HP)</th>
|
||||||
<th>Role</th>
|
<th>Role</th>
|
||||||
<th>Nomor Induk</th>
|
<th>NISN / NIP</th>
|
||||||
<th>Aksi</th>
|
<th>Kelas / Golongan</th>
|
||||||
|
<th class="text-center">Aksi</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@forelse($users as $index => $user)
|
@forelse($users as $index => $user)
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ $index + 1 }}</td>
|
<td>{{ $users->firstItem() + $index }}</td>
|
||||||
<td>{{ $user->name }}</td>
|
<td class="fw-bold">{{ $user->name }}</td>
|
||||||
<td>{{ $user->email }}</td>
|
|
||||||
<td>
|
<td>
|
||||||
<span class="badge {{ $user->role == 'guru' ? 'bg-info' : 'bg-primary' }}">
|
<div>{{ $user->email }}</div>
|
||||||
{{ ucfirst($user->role) }}
|
<div class="small text-muted"><i class="bi bi-telephone me-1"></i>{{ $user->no_hp ?? '-' }}</div>
|
||||||
</span>
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ $user->nisn ?? $user->nip ?? '-' }}
|
@if($user->role == 'guru')
|
||||||
|
<span class="badge bg-info text-dark">Guru</span>
|
||||||
|
@elseif($user->role == 'siswa')
|
||||||
|
<span class="badge bg-primary">Siswa</span>
|
||||||
|
@else
|
||||||
|
<span class="badge bg-secondary">Petugas</span>
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
<td class="font-monospace text-primary">
|
||||||
|
{{ $user->nisn ?? ($user->nip ?? '-') }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ route('admin.pengguna.edit', $user->id) }}" class="btn btn-sm btn-warning">
|
@if($user->role == 'siswa')
|
||||||
|
<span class="badge bg-light text-black border">Kelas: {{ $user->kelas ?? '-' }} / {{ $user->golongan ?? '-' }}</span>
|
||||||
|
@else
|
||||||
|
-
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
<td class="text-center">
|
||||||
|
<a href="{{ route('admin.pengguna.edit', $user->id) }}"
|
||||||
|
class="btn btn-sm btn-warning">
|
||||||
<i class="bi bi-pencil"></i> Edit
|
<i class="bi bi-pencil"></i> Edit
|
||||||
</a>
|
</a>
|
||||||
<form action="{{ route('admin.pengguna.destroy', $user->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Yakin hapus user ini?')">
|
<form action="{{ route('admin.pengguna.destroy', $user->id) }}" method="POST"
|
||||||
|
class="d-inline" onsubmit="return confirm('Yakin hapus user ini?')">
|
||||||
@csrf
|
@csrf
|
||||||
@method('DELETE')
|
@method('DELETE')
|
||||||
<button class="btn btn-sm btn-danger"><i class="bi bi-trash"></i></button>
|
<button class="btn btn-sm btn-danger"><i class="bi bi-trash"></i></button>
|
||||||
|
|
@ -50,7 +70,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
@empty
|
@empty
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-center">Belum ada pengguna terdaftar.</td>
|
<td colspan="7" class="text-center py-4 text-muted">Belum ada pengguna terdaftar.</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforelse
|
@endforelse
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
@ -66,6 +86,7 @@
|
||||||
|
|
||||||
<hr class="my-5 border-4">
|
<hr class="my-5 border-4">
|
||||||
|
|
||||||
|
{{-- BAGIAN DATA INDUK (WHITELIST) --}}
|
||||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
<div>
|
<div>
|
||||||
<h4 class="fw-bold text-success mb-1">
|
<h4 class="fw-bold text-success mb-1">
|
||||||
|
|
@ -100,15 +121,19 @@
|
||||||
<td class="fw-bold font-monospace">{{ $item->nomor_induk }}</td>
|
<td class="fw-bold font-monospace">{{ $item->nomor_induk }}</td>
|
||||||
<td>{{ $item->nama_pemilik }}</td>
|
<td>{{ $item->nama_pemilik }}</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="badge {{ $item->role == 'guru' ? 'bg-info' : 'bg-secondary' }}">
|
@if($item->role == 'guru')
|
||||||
{{ ucfirst($item->role) }}
|
<span class="badge bg-info text-dark">Guru</span>
|
||||||
</span>
|
@elseif($item->role == 'siswa')
|
||||||
|
<span class="badge bg-primary">Siswa</span>
|
||||||
|
@else
|
||||||
|
<span class="badge bg-secondary">Petugas</span>
|
||||||
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
{{-- Cek apakah user sudah daftar pakai NIP ini --}}
|
|
||||||
@php
|
@php
|
||||||
$isRegistered = \App\Models\User::where('nisn', $item->nomor_induk)
|
$isRegistered = \App\Models\User::where('nisn', $item->nomor_induk)
|
||||||
->orWhere('nip', $item->nomor_induk)->exists();
|
->orWhere('nip', $item->nomor_induk)
|
||||||
|
->exists();
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
@if ($isRegistered)
|
@if ($isRegistered)
|
||||||
|
|
@ -122,7 +147,9 @@
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td class="text-end">
|
<td class="text-end">
|
||||||
<form action="{{ route('admin.master-induk.destroy', $item->id) }}" method="POST" onsubmit="return confirm('Hapus data ini? User dengan NIP/NISN ini tidak akan bisa daftar lagi.');">
|
<form action="{{ route('admin.master-induk.destroy', $item->id) }}"
|
||||||
|
method="POST"
|
||||||
|
onsubmit="return confirm('Hapus data ini? User dengan NIP/NISN ini tidak akan bisa daftar lagi.');">
|
||||||
@csrf
|
@csrf
|
||||||
@method('DELETE')
|
@method('DELETE')
|
||||||
<button type="submit" class="btn btn-sm btn-outline-danger">
|
<button type="submit" class="btn btn-sm btn-outline-danger">
|
||||||
|
|
@ -167,17 +194,20 @@
|
||||||
<select name="role" class="form-select" required>
|
<select name="role" class="form-select" required>
|
||||||
<option value="siswa">Siswa</option>
|
<option value="siswa">Siswa</option>
|
||||||
<option value="guru">Guru</option>
|
<option value="guru">Guru</option>
|
||||||
|
<option value="penjaga perpus">Petugas Perpustakaan</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">NIP / NISN</label>
|
<label class="form-label">NIP / NISN</label>
|
||||||
<input type="number" name="nomor_induk" class="form-control" placeholder="Contoh: 1234567890" required>
|
<input type="number" name="nomor_induk" class="form-control"
|
||||||
|
placeholder="Contoh: 1234567890" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Nama Pemilik</label>
|
<label class="form-label">Nama Pemilik</label>
|
||||||
<input type="text" name="nama_pemilik" class="form-control" placeholder="Nama Siswa/Guru..." required>
|
<input type="text" name="nama_pemilik" class="form-control"
|
||||||
|
placeholder="Nama Siswa/Guru..." required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,9 @@
|
||||||
|
|
||||||
Route::get('/pengguna', [AdminUserController::class, 'index'])->name('pengguna.index');
|
Route::get('/pengguna', [AdminUserController::class, 'index'])->name('pengguna.index');
|
||||||
Route::get('/pengguna/tambah', [AdminUserController::class, 'create'])->name('pengguna.create');
|
Route::get('/pengguna/tambah', [AdminUserController::class, 'create'])->name('pengguna.create');
|
||||||
|
Route::post('/pengguna', [AdminUserController::class, 'store'])->name('pengguna.store');
|
||||||
Route::get('/pengguna/{id}/edit', [AdminUserController::class, 'edit'])->name('pengguna.edit');
|
Route::get('/pengguna/{id}/edit', [AdminUserController::class, 'edit'])->name('pengguna.edit');
|
||||||
|
Route::patch('/pengguna/{id}', [AdminUserController::class, 'update'])->name('pengguna.update');
|
||||||
Route::delete('/pengguna/{id}', [AdminUserController::class, 'destroy'])->name('pengguna.destroy');
|
Route::delete('/pengguna/{id}', [AdminUserController::class, 'destroy'])->name('pengguna.destroy');
|
||||||
|
|
||||||
Route::get('/pengumuman', [AdminPengumumanController::class, 'index'])->name('pengumuman.index');
|
Route::get('/pengumuman', [AdminPengumumanController::class, 'index'])->name('pengumuman.index');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue