daftar guru update
This commit is contained in:
parent
aaddeafaae
commit
788282c3c4
|
|
@ -15,7 +15,7 @@ public function dashboard(){
|
|||
$totalSiswa = Siswa::count();
|
||||
$totalKelas = Kelas::count();
|
||||
$totalMapel = Mapel::count();
|
||||
$chartData = Kelas::withCount('siswas')->get();
|
||||
$chartData = Kelas::withCount('siswa')->get();
|
||||
$latestChallenges = Challenge::latest()->take(3)->get();
|
||||
return view('admin.dashboard', compact('totalGuru','totalSiswa','totalKelas','totalMapel','chartData','latestChallenges'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Guru;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class GuruController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Guru::query();
|
||||
|
||||
// SEARCH
|
||||
if ($request->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('admin.guru.index', compact('gurus'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('admin.guru.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'nip' => 'required|string|max:30|unique:gurus,nip',
|
||||
'nama' => 'required|string|max:100',
|
||||
'password' => 'required|string|min:6',
|
||||
], [
|
||||
'nip.required' => 'NIP wajib diisi',
|
||||
'nip.unique' => 'NIP sudah terdaftar',
|
||||
'nama.required' => 'Nama wajib diisi',
|
||||
'password.required' => 'Password wajib diisi',
|
||||
'password.min' => 'Password minimal 6 karakter',
|
||||
]);
|
||||
|
||||
Guru::create([
|
||||
'nip' => $validated['nip'],
|
||||
'nama' => $validated['nama'],
|
||||
'password' => Hash::make($validated['password']),
|
||||
]);
|
||||
|
||||
return redirect()->route('admin.guru.index')
|
||||
->with('success', 'Data guru berhasil ditambahkan!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $nip)
|
||||
{
|
||||
$guru = Guru::findOrFail($nip);
|
||||
return view('admin.guru.show', compact('guru'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $nip)
|
||||
{
|
||||
$guru = Guru::findOrFail($nip);
|
||||
return view('admin.guru.edit', compact('guru'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $nip)
|
||||
{
|
||||
$guru = Guru::findOrFail($nip);
|
||||
|
||||
$validated = $request->validate([
|
||||
'nama' => 'required|string|max:100',
|
||||
'password' => 'nullable|string|min:6',
|
||||
], [
|
||||
'nama.required' => 'Nama wajib diisi',
|
||||
'password.min' => 'Password minimal 6 karakter',
|
||||
]);
|
||||
|
||||
$guru->nama = $validated['nama'];
|
||||
|
||||
// Update password hanya jika diisi
|
||||
if ($request->filled('password')) {
|
||||
$guru->password = Hash::make($validated['password']);
|
||||
}
|
||||
|
||||
$guru->save();
|
||||
|
||||
return redirect()->route('admin.guru.index')
|
||||
->with('success', 'Data guru berhasil diupdate!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $nip)
|
||||
{
|
||||
$guru = Guru::findOrFail($nip);
|
||||
$guru->delete();
|
||||
|
||||
return redirect()->route('admin.guru.index')
|
||||
->with('success', 'Data guru berhasil dihapus!');
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
class Guru extends Model
|
||||
{
|
||||
protected $table = 'guru'; // INI PENTING!
|
||||
protected $table = 'gurus';
|
||||
|
||||
protected $primaryKey = 'nip';
|
||||
|
||||
|
|
@ -17,7 +17,10 @@ class Guru extends Model
|
|||
protected $fillable = [
|
||||
'nip',
|
||||
'nama',
|
||||
'email',
|
||||
'password'
|
||||
];
|
||||
}
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
}
|
||||
|
|
@ -19,4 +19,10 @@ class Kelas extends Model
|
|||
'nama_kelas',
|
||||
'tingkat',
|
||||
];
|
||||
|
||||
public function siswa()
|
||||
{
|
||||
return $this->hasMany(Siswa::class, 'id_kelas', 'id_kelas');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -27,4 +27,10 @@ class Siswa extends Model
|
|||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
|
||||
public function kelas()
|
||||
{
|
||||
return $this->belongsTo(Kelas::class, 'id_kelas', 'id_kelas');
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 163 B |
Binary file not shown.
|
After Width: | Height: | Size: 242 B |
Binary file not shown.
|
After Width: | Height: | Size: 244 B |
Binary file not shown.
|
After Width: | Height: | Size: 258 B |
Binary file not shown.
|
After Width: | Height: | Size: 272 B |
Binary file not shown.
|
After Width: | Height: | Size: 423 B |
|
|
@ -1,31 +1,309 @@
|
|||
@extends('admin.layouts.app')
|
||||
@section('title','Daftar Guru')
|
||||
|
||||
@section('title', 'Daftar Guru')
|
||||
|
||||
@section('content')
|
||||
<div class="card p-4">
|
||||
<div class="d-flex justify-content-between mb-3">
|
||||
<h4>Daftar Guru</h4>
|
||||
<a href="{{ route('admin.guru.create') }}" class="btn btn-primary">Tambah Guru</a>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead><tr><th>#</th><th>Nama</th><th>Email</th><th>Aksi</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach($gurus as $g)
|
||||
<tr>
|
||||
<td>{{ $loop->iteration }}</td>
|
||||
<td>{{ $g->name }}</td>
|
||||
<td>{{ $g->email }}</td>
|
||||
<td>
|
||||
<a href="{{ route('admin.guru.edit', $g) }}" class="btn btn-sm btn-outline-secondary">Edit</a>
|
||||
<form action="{{ route('admin.guru.destroy', $g) }}" method="POST" style="display:inline">@csrf @method('DELETE')
|
||||
<button class="btn btn-sm btn-danger" onclick="return confirm('Hapus?')">Hapus</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<style>
|
||||
.page-title {
|
||||
font-size: 30px;
|
||||
font-weight: 800;
|
||||
margin-bottom: 10px;
|
||||
margin-top: -20px;
|
||||
}
|
||||
|
||||
.custom-card {
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
border: 2px solid #e5e5e5;
|
||||
padding: 25px;
|
||||
}
|
||||
|
||||
.btn-primary-custom {
|
||||
background: #2b8ef3;
|
||||
color: white;
|
||||
border-radius: 10px;
|
||||
padding: 8px 18px;
|
||||
border: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 14px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.table-header {
|
||||
background: #a5e6ba;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
background: #a5e6ba;
|
||||
border-radius: 30px;
|
||||
padding: 6px 15px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.search-box input {
|
||||
border: none;
|
||||
outline: none;
|
||||
background: transparent;
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
width: 20px;
|
||||
cursor: pointer;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.per-page-select {
|
||||
border-radius: 10px;
|
||||
padding: 5px;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
/* ===== STYLE BARU UNTUK MODAL ===== */
|
||||
|
||||
.modal-header-pastel {
|
||||
background: #FFD97D !important;
|
||||
color: black !important;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
border-radius: 15px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.modal-body label {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.modal {
|
||||
left: auto !important;
|
||||
right: 0;
|
||||
width: calc(100% - 250px);
|
||||
}
|
||||
|
||||
.modal-backdrop {
|
||||
left: auto !important;
|
||||
right: 0;
|
||||
width: calc(100% - 250px);
|
||||
}
|
||||
|
||||
.modal-dialog {
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<h3 class="page-title">DAFTAR GURU</h3>
|
||||
|
||||
<div class="custom-card">
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<button class="btn-primary-custom" data-bs-toggle="modal" data-bs-target="#modalTambah">
|
||||
<img src="{{ asset('images/icon/main/add.png') }}" width="18">
|
||||
Tambah Data
|
||||
</button>
|
||||
|
||||
<button class="btn-primary-custom">
|
||||
<img src="{{ asset('images/icon/main/download.png') }}" width="18">
|
||||
Download PDF
|
||||
</button>
|
||||
|
||||
<button class="btn-primary-custom">
|
||||
<img src="{{ asset('images/icon/main/download.png') }}" width="18">
|
||||
Download Excel
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form method="GET" action="{{ route('admin.guru.index') }}">
|
||||
<div class="search-box">
|
||||
<input type="text" name="search" placeholder="Cari" value="{{ request('search') }}">
|
||||
<button style="border:none;background:none">
|
||||
<img src="{{ asset('images/icon/main/search.png') }}" width="18">
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<form method="GET" class="mb-2">
|
||||
<span>Tampilkan</span>
|
||||
|
||||
<select name="perPage" onchange="this.form.submit()" class="per-page-select">
|
||||
<option value="10" {{ request('perPage') == 10 ? 'selected' : '' }}>10</option>
|
||||
<option value="25" {{ request('perPage') == 25 ? 'selected' : '' }}>25</option>
|
||||
<option value="50" {{ request('perPage') == 50 ? 'selected' : '' }}>50</option>
|
||||
<option value="100" {{ request('perPage') == 100 ? 'selected' : '' }}>100</option>
|
||||
</select>
|
||||
|
||||
<span>data</span>
|
||||
|
||||
<input type="hidden" name="search" value="{{ request('search') }}">
|
||||
</form>
|
||||
|
||||
<table class="table text-center align-middle">
|
||||
<thead class="table-header">
|
||||
<tr>
|
||||
<th>No</th>
|
||||
<th>Nama Lengkap</th>
|
||||
<th>NIP</th>
|
||||
<th>Password</th>
|
||||
<th>Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@forelse($gurus as $index => $guru)
|
||||
<tr>
|
||||
<td>{{ $gurus->firstItem() + $index }}</td>
|
||||
<td>{{ $guru->nama }}</td>
|
||||
<td>{{ $guru->nip }}</td>
|
||||
<td>********</td>
|
||||
|
||||
<td>
|
||||
<button onclick="openEditModal('{{ $guru->nip }}', '{{ $guru->nama }}')"
|
||||
style="border:none;background:none">
|
||||
<img src="{{ asset('images/icon/main/edit.png') }}" class="action-icon">
|
||||
</button>
|
||||
|
||||
<form action="{{ route('admin.guru.destroy', $guru->nip) }}"
|
||||
method="POST" class="d-inline"
|
||||
onsubmit="return confirm('Yakin ingin menghapus data?')">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" style="border:none;background:none">
|
||||
<img src="{{ asset('images/icon/main/del.png') }}" class="action-icon">
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="5">Belum ada data guru</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="d-flex justify-content-end">
|
||||
{{ $gurus->links() }}
|
||||
</div>
|
||||
|
||||
{{ $gurus->links() }}
|
||||
</div>
|
||||
|
||||
{{-- MODAL TAMBAH DATA --}}
|
||||
<div class="modal fade" id="modalTambah" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
|
||||
<div class="modal-header modal-header-pastel">
|
||||
<h5 class="modal-title">Tambah Data Guru</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<form action="{{ route('admin.guru.store') }}" method="POST">
|
||||
@csrf
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>NIP <span class="text-danger">*</span></label>
|
||||
<input type="text" name="nip" class="form-control" placeholder="Masukkan NIP" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Nama Lengkap <span class="text-danger">*</span></label>
|
||||
<input type="text" name="nama" class="form-control" placeholder="Masukkan nama lengkap" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Password <span class="text-danger">*</span></label>
|
||||
<input type="password" name="password" class="form-control" placeholder="Minimal 6 karakter" required>
|
||||
<small class="text-muted">Password akan di-hash otomatis</small>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
|
||||
<button type="submit" class="btn btn-success">Simpan Data</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- MODAL EDIT DATA --}}
|
||||
<div class="modal fade" id="modalEdit" tabindex="-1">
|
||||
<div class="modal-dialog modal-lg modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
|
||||
<div class="modal-header modal-header-pastel">
|
||||
<h5 class="modal-title">Edit Data Guru</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<form id="formEdit" method="POST">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>NIP</label>
|
||||
<input type="text" id="editNip" class="form-control" disabled>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Nama Lengkap <span class="text-danger">*</span></label>
|
||||
<input type="text" name="nama" id="editNama" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Password Baru (Opsional)</label>
|
||||
<input type="password" name="password" class="form-control" placeholder="Isi jika ingin mengganti password">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
|
||||
<button type="submit" class="btn btn-save-pastel">Update Data</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function openEditModal(nip, nama) {
|
||||
document.getElementById('editNip').value = nip;
|
||||
document.getElementById('editNama').value = nama;
|
||||
|
||||
document.getElementById('formEdit').action = "{{ url('admin/guru') }}/" + nip;
|
||||
|
||||
new bootstrap.Modal(document.getElementById('modalEdit')).show();
|
||||
}
|
||||
</script>
|
||||
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
@extends('admin.layouts.app')
|
||||
|
||||
@section('title', 'Detail Guru')
|
||||
|
||||
@section('content')
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header bg-info text-white">
|
||||
<h4 class="mb-0">Detail Data Guru</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-borderless">
|
||||
<tr>
|
||||
<th width="30%">NIP</th>
|
||||
<td>: {{ $guru->nip }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Nama Lengkap</th>
|
||||
<td>: {{ $guru->nama }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Tanggal Dibuat</th>
|
||||
<td>: {{ $guru->created_at->format('d F Y, H:i') }} WIB</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Terakhir Update</th>
|
||||
<td>: {{ $guru->updated_at->format('d F Y, H:i') }} WIB</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="d-flex justify-content-between mt-4">
|
||||
<a href="{{ route('admin.guru.index') }}" class="btn btn-secondary">
|
||||
<i class="bi bi-arrow-left"></i> Kembali
|
||||
</a>
|
||||
<div>
|
||||
<a href="{{ route('admin.guru.edit', $guru->nip) }}" class="btn btn-warning text-white">
|
||||
<i class="bi bi-pencil"></i> Edit Data
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
@ -6,8 +6,9 @@
|
|||
|
||||
use App\Http\Controllers\Admin\LoginController;
|
||||
use App\Http\Controllers\Admin\AdminController;
|
||||
use App\Http\Controllers\Admin\GuruController;
|
||||
|
||||
use App\Http\Controllers\GuruController;
|
||||
// use App\Http\Controllers\GuruController;
|
||||
use App\Http\Controllers\SiswaController;
|
||||
use App\Http\Controllers\KelasController;
|
||||
use App\Http\Controllers\MapelController;
|
||||
|
|
|
|||
Loading…
Reference in New Issue