From b7cec503d1eb0fc943b8b80e840b7763a70169d9 Mon Sep 17 00:00:00 2001 From: rendygaafk Date: Sat, 17 May 2025 02:24:00 +0700 Subject: [PATCH] fix history pengumuman --- .../Controllers/AnnouncementController.php | 13 +++- .../admin/announcement/history.blade.php | 63 ++++++++++--------- routes/web.php | 1 + 3 files changed, 47 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/AnnouncementController.php b/app/Http/Controllers/AnnouncementController.php index 7896771..491cda0 100644 --- a/app/Http/Controllers/AnnouncementController.php +++ b/app/Http/Controllers/AnnouncementController.php @@ -155,20 +155,31 @@ public function details($id) public function destroy($id) { + DB::beginTransaction(); + try { $announcement = Announcement::findOrFail($id); + + // Hapus relasi terlebih dahulu + $announcement->ruangans()->detach(); + + // Kemudian hapus pengumuman $announcement->delete(); + DB::commit(); + return response()->json([ 'success' => true, 'message' => 'Pengumuman berhasil dihapus' ]); } catch (\Exception $e) { + DB::rollBack(); Log::error('Failed to delete announcement: ' . $e->getMessage()); + return response()->json([ 'success' => false, - 'message' => 'Gagal menghapus pengumuman' + 'message' => 'Gagal menghapus pengumuman: ' . $e->getMessage() ], 500); } } diff --git a/resources/views/admin/announcement/history.blade.php b/resources/views/admin/announcement/history.blade.php index a764503..e9ca44d 100644 --- a/resources/views/admin/announcement/history.blade.php +++ b/resources/views/admin/announcement/history.blade.php @@ -6,18 +6,21 @@
-
+

- Filter Riwayat + Filter Riwayat

@@ -25,7 +28,7 @@ class="flex items-center mt-4 md:mt-0 px-4 py-2 bg-white border border-blue-500
- @@ -39,7 +42,7 @@ class="flex items-center mt-4 md:mt-0 px-4 py-2 bg-white border border-blue-500
+ class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md border bg-white">
@@ -49,7 +52,7 @@ class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none
+ class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md border bg-white">
@@ -73,11 +76,8 @@ class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none
- + - @@ -96,27 +96,31 @@ class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none - @forelse($announcements as $index => $announcement) - - + @forelse($announcements as $announcement) + @@ -128,7 +132,7 @@ class="block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none
@foreach($announcement->ruangans as $ruangan) - + {{ $ruangan->nama_ruangan }} @endforeach @@ -154,7 +158,7 @@ class="inline-flex items-center px-3 py-1.5 border border-transparent text-sm fo
- # - Waktu Pengiriman
- {{ $index + 1 + (($announcements->currentPage() - 1) * $announcements->perPage()) }} -
-
- {{ $announcement->formatted_sent_at }} -
-
- {{ $announcement->sent_at->diffForHumans() }} +
+
+ +
+
+
+ {{ $announcement->formatted_sent_at }} +
+
+ {{ $announcement->sent_at->diffForHumans() }} +
+
@if($announcement->mode === 'tts') - - TTS + + TTS @else - - Manual + + Manual @endif
`, diff --git a/routes/web.php b/routes/web.php index 39f678e..8f142cc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -110,6 +110,7 @@ Route::prefix('announcement')->controller(AnnouncementController::class)->group(function () { Route::get('/', 'index')->name('admin.announcement.index'); Route::get('/history', 'history')->name('admin.announcement.history'); + Route::delete('/{id}', 'destroy')->name('announcement.destroy'); }); });