where('id', $id)->first(); $transactions = Transaction::with(['treatment']) ->where('patien_registration_id', $id) ->get(); $treatments = Treatment::all(); // Pass the data to the view return view('registration.transaction.index', compact('registration', 'transactions', 'treatments')); } public function store(Request $request, $id) { // Validate the request data $validatedData = $request->validate([ 'treatment_id' => 'required|exists:treatments,id', 'amount' => 'required|numeric|min:0', ]); // Create a new transaction Transaction::create([ 'patien_registration_id' => $id, 'treatment_id' => $validatedData['treatment_id'], 'amount' => $validatedData['amount'], 'user_id' => auth()->user()->id, ]); // Redirect back with a success message return redirect()->back()->with('success', 'Transaksi berhasil ditambahkan.'); } public function update(Request $request, $transId) { // Validate the request data $validatedData = $request->validate([ 'treatment_id' => 'required|exists:treatments,id', 'amount' => 'required|numeric|min:0', ]); // Find the transaction and update it $transaction = Transaction::findOrFail($transId); $transaction->update([ 'treatment_id' => $validatedData['treatment_id'], 'amount' => $validatedData['amount'], ]); // Redirect back with a success message return redirect()->back()->with('success', 'Transaksi berhasil diperbarui.'); } public function destroy($transId) { // Find the transaction and delete it $transaction = Transaction::findOrFail($transId); $transaction->delete(); // Redirect back with a success message return redirect()->back()->with('success', 'Transaksi berhasil dihapus.'); } }