input('tanggal') ? Carbon::parse($request->input('tanggal'))->format('Y-m-d') : now()->format('Y-m-d'); // Parse tanggal untuk query $tanggalCarbon = Carbon::parse($tanggal)->startOfDay(); // Ambil data history perhitungan untuk tanggal yang dipilih $bobotKriteria = [ $tanggal => BobotKriteria::with('kriteria') ->whereDate('created_at', $tanggalCarbon) ->orderBy('created_at', 'desc') ->get() ]; $perbandinganKriteria = [ $tanggal => PerbandinganKriteria::with(['kriteria1', 'kriteria2']) ->whereDate('created_at', $tanggalCarbon) ->orderBy('created_at', 'desc') ->get() ]; $perbandinganAlternatif = [ $tanggal => PerbandinganAlternatif::with(['alternatif1', 'alternatif2', 'kriteria']) ->whereDate('created_at', $tanggalCarbon) ->orderBy('created_at', 'desc') ->get() ]; $consistencyRatios = [ $tanggal => ConsistencyRatioAlternatif::with(['kriteria', 'komponen']) ->whereDate('created_at', $tanggalCarbon) ->orderBy('created_at', 'desc') ->get() ]; $skorMakanan = [ $tanggal => SkorMakanan::with(['makanan', 'kriteria']) ->whereDate('created_at', $tanggalCarbon) ->orderBy('created_at', 'desc') ->get() ]; // Filter out empty collections $bobotKriteria = array_filter($bobotKriteria, function($collection) { return $collection->isNotEmpty(); }); $perbandinganKriteria = array_filter($perbandinganKriteria, function($collection) { return $collection->isNotEmpty(); }); $perbandinganAlternatif = array_filter($perbandinganAlternatif, function($collection) { return $collection->isNotEmpty(); }); $consistencyRatios = array_filter($consistencyRatios, function($collection) { return $collection->isNotEmpty(); }); $skorMakanan = array_filter($skorMakanan, function($collection) { return $collection->isNotEmpty(); }); return view('admin.history.ahp', compact( 'bobotKriteria', 'perbandinganKriteria', 'perbandinganAlternatif', 'consistencyRatios', 'skorMakanan', 'tanggal' )); } catch (\Exception $e) { return redirect()->back()->with('error', 'Terjadi kesalahan saat memuat data history: ' . $e->getMessage()); } } }