From 3c4f35a37729de01f364d95129106aa206fe0e3b Mon Sep 17 00:00:00 2001 From: whywdd Date: Wed, 5 Mar 2025 20:49:21 +0700 Subject: [PATCH] update tgl 5 maret --- app/Http/Controllers/GajiController.php | 20 ++++++++++ resources/views/Gaji.Blade.php | 32 ++++++++++++++-- resources/views/GajiEdit.blade.php | 50 +++++++++++++++++++++++++ routes/web.php | 3 ++ 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 resources/views/GajiEdit.blade.php diff --git a/app/Http/Controllers/GajiController.php b/app/Http/Controllers/GajiController.php index 33e51b7..f76fa49 100644 --- a/app/Http/Controllers/GajiController.php +++ b/app/Http/Controllers/GajiController.php @@ -24,4 +24,24 @@ public function show($id) $karyawan = GajiModel::findOrFail($id); return response()->json($karyawan); } + + public function edit($id) + { + $karyawan = GajiModel::findOrFail($id); + return view('GajiEdit', compact('karyawan')); + } + + public function update(Request $request, $id) + { + $karyawan = GajiModel::findOrFail($id); + $karyawan->update($request->all()); + return redirect()->route('gaji.index')->with('success', 'Data gaji berhasil diperbarui'); + } + + public function destroy($id) + { + $karyawan = GajiModel::findOrFail($id); + $karyawan->delete(); + return response()->json(['success' => true]); + } } \ No newline at end of file diff --git a/resources/views/Gaji.Blade.php b/resources/views/Gaji.Blade.php index 77a375c..7fd1fa4 100644 --- a/resources/views/Gaji.Blade.php +++ b/resources/views/Gaji.Blade.php @@ -54,10 +54,14 @@ class="border rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-bl Rp {{ number_format($gaji->gaji, 0, ',', '.') }}
- -
@@ -110,6 +114,28 @@ function filterTable() { } } } + +function deleteGaji(id) { + if (confirm('Apakah Anda yakin ingin menghapus data ini?')) { + fetch(`/gaji/${id}`, { + method: 'DELETE', + headers: { + 'X-CSRF-TOKEN': '{{ csrf_token() }}', + 'Content-Type': 'application/json' + }, + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + window.location.reload(); + } + }) + .catch(error => { + console.error('Error:', error); + alert('Terjadi kesalahan saat menghapus data'); + }); + } +}