validate([ 'nfc_type' => 'required', 'nfc_following' => 'required', 'nfc_expiration' => 'required|date', 'nfc_amount' => 'required|numeric', 'nfc_next' => 'required', 'nfc_select' => 'required|in:active,deactivated', ]); // Guardar los datos en la base de datos DB::beginTransaction(); try { $nfc_voucher->nfc_type = $validatedData['nfc_type']; $nfc_voucher->nfc_following = $validatedData['nfc_following']; $nfc_voucher->nfc_expiration = $validatedData['nfc_expiration']; $nfc_voucher->nfc_amount = $validatedData['nfc_amount']; $nfc_voucher->nfc_next = $validatedData['nfc_next']; $nfc_voucher->nfc_select = $validatedData['nfc_select']; $nfc_voucher->save(); DB::commit(); // Redireccionar o mostrar un mensaje de éxito // Redireccionar a la ruta '/pos-activation' return redirect()->route('pos.configuration')->with('toast_success', '¡Política de empresa creada con éxito!'); } catch (\Exception $e) { DB::rollback(); // Manejar el error y mostrar un mensaje de error // } } /** * Display the specified resource. * * @param \App\Models\NfcVoucher $nfcVoucher * @return \Illuminate\Http\Response */ public function show(NfcVoucher $nfcVoucher) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\NfcVoucher $nfcVoucher * @return \Illuminate\Http\Response */ public function edit(NfcVoucher $nfcVoucher) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\NfcVoucher $nfcVoucher * @return \Illuminate\Http\Response */ public function update(Request $request, NfcVoucher $nfcVoucher) { // } /** * Remove the specified resource from storage. * * @param \App\Models\NfcVoucher $nfcVoucher * @return \Illuminate\Http\Response */ public function collection() { return Excel::download(new NfcVoucherExportsCollection, 'Nfc_Voucher.xlsx'); } public function view() { // return Excel::download(new NfcVoucherExportsView, 'Nfc_Voucher.xlsx'); $nfc_vouchers = NfcVoucher::latest()->get();// Obtén los datos de la tabla desde tu controlador o modelo return Excel::download(new NfcVoucherExportsView($nfc_vouchers), 'nfc_vouchers.xlsx'); } }