diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index ec960d6..42a0891 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -5,6 +5,8 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; +use App\Models\Biodata; +use Carbon\Carbon; class AdminController extends Controller { @@ -36,18 +38,63 @@ public function authenticate(Request $request) } public function dashboard() - { - if (!Auth::check()) { - return redirect()->route('admin.login'); - } +{ + // total diagnosis + $totalDiagnosis = Biodata::count(); - // Get statistics - $stats = $this->getStatistics(); - - return view('admin.dashboard', [ - 'stats' => $stats - ]); - } + // hari ini + $todayDiagnosis = Biodata::whereDate('created_at', Carbon::today())->count(); + + // total user + $totalUsers = Biodata::count(); + + // penyakit paling umum + $mostCommon = Biodata::select('hasil_diagnosis') + ->whereNotNull('hasil_diagnosis') + ->groupBy('hasil_diagnosis') + ->orderByRaw('COUNT(*) DESC') + ->value('hasil_diagnosis'); + + // diagnosis terbaru + $recent = Biodata::select('hasil_diagnosis', 'created_at') + ->latest() + ->take(5) + ->get(); + + // format tabel + $recentFormatted = $recent->map(function ($item) { + return [ + 'date' => $item->created_at, + 'disease' => $item->hasil_diagnosis, + 'count' => 1 + ]; + }); + + // 🔥 CHART (HARUS DI LUAR MAP) + $diseaseStats = Biodata::select('hasil_diagnosis') + ->whereNotNull('hasil_diagnosis') + ->get() + ->groupBy('hasil_diagnosis') + ->map(function ($item) { + return count($item); + }); + + $chartLabels = $diseaseStats->keys()->values(); + $chartData = $diseaseStats->values(); + + // kirim ke blade + $stats = [ + 'total_diagnosis' => $totalDiagnosis, + 'today_diagnosis' => $todayDiagnosis, + 'total_users' => $totalUsers, + 'most_common_disease' => $mostCommon, + 'recent_diagnosis' => $recentFormatted, + 'chart_labels' => $chartLabels, + 'chart_data' => $chartData + ]; + + return view('admin.dashboard', compact('stats')); +} public function logout(Request $request) { diff --git a/app/Http/Controllers/DiagnosisController.php b/app/Http/Controllers/DiagnosisController.php index 3b28509..cc8d44f 100644 --- a/app/Http/Controllers/DiagnosisController.php +++ b/app/Http/Controllers/DiagnosisController.php @@ -14,7 +14,7 @@ public function prosesDiagnosis(Request $request) // validasi minimal 3 gejala if (count($input) < 3) { return redirect()->route('gejala') - ->with('error', 'Pilih minimal 3 gejala!'); + ->with('error', 'Pilih minimal 5 dan maksimal 7 gejala!'); } $inputNama = $input; diff --git a/database/migrations/2026_04_03_133848_add_columns_to_biodata.php b/database/migrations/2026_04_03_133848_add_columns_to_biodata.php new file mode 100644 index 0000000..976e939 --- /dev/null +++ b/database/migrations/2026_04_03_133848_add_columns_to_biodata.php @@ -0,0 +1,28 @@ +
+
+ +
@@ -350,7 +357,7 @@
📊
-
+12 hari ini
+
+{{ $stats['today_diagnosis'] }} hari ini
@@ -375,7 +382,7 @@
Pengguna aktif
-
+
{{ $stats['most_common_disease'] }}
@@ -436,6 +443,32 @@
@include('components.scroll-top') + + + + diff --git a/resources/views/gejala.blade.php b/resources/views/gejala.blade.php index ee20a74..2b2d19e 100644 --- a/resources/views/gejala.blade.php +++ b/resources/views/gejala.blade.php @@ -780,13 +780,13 @@
-
+ @csrf
💡
-

Pilih semua gejala yang Anda amati pada kucing Anda. Semakin banyak gejala yang dipilih, semakin akurat diagnosis yang akan diberikan.

+

Pilih minimal 4 dan maksimal 7 gejala yang terjadi pada kucing anda

@@ -848,7 +848,6 @@ class="gejala-checkbox" const selectedCount = document.getElementById('selectedCount'); const form = document.getElementById('gejalaForm'); -// Update selected count function updateSelectedCount() { const checked = document.querySelectorAll('.gejala-checkbox:checked').length; selectedCount.textContent = checked + ' dipilih'; @@ -858,7 +857,7 @@ function updateSelectedCount() { setTimeout(() => selectedCount.classList.remove('animate'), 500); // Enable/disable submit button - if (checked > 0) { + if (checked >= 4 && checked <= 7) { submitBtn.disabled = false; submitBtn.style.opacity = '1'; } else { @@ -874,7 +873,21 @@ function updateSelectedCount() { // Form submission +form.addEventListener('submit', function(e) { + const checked = document.querySelectorAll('.gejala-checkbox:checked').length; + if (checked < 5) { + e.preventDefault(); + alert("Minimal pilih 4 gejala!"); + return; + } + + if (checked > 7) { + e.preventDefault(); + alert("Maksimal hanya 7 gejala!"); + return; + } +}); // Search functionality const searchInput = document.getElementById('searchGejala');