request->isAJAX()) { $user = auth()->user()->id; $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); $reqData = $this->request->getPost(); $pedido_id = $reqData['pedido_id'] ?? 0; $presupuestos_id = $reqData['presupuestos_id'] ?? 0; $return_data = $this->model->generarAlbaranes($pedido_id, $presupuestos_id, $user); $data = [ 'data' => $return_data, $csrfTokenName => $newTokenHash ]; return $this->respond($data); } else { return $this->failUnauthorized('Invalid request', 403); } } public function update($id = null){ if ($this->request->isAJAX()) { $newTokenHash = csrf_hash(); $csrfTokenName = csrf_token(); if ($id == null) : return $this->redirect2listView(); endif; $id = filter_var($id, FILTER_SANITIZE_URL); $albaranEntity = $this->model->find($id); if ($albaranEntity == false) : $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Pedidos.albaran')), $id]); return $this->redirect2listView('sweet-error', $message); endif; if ($this->request->getPost()) : $nullIfEmpty = true; // !(phpversion() >= '8.1'); $postData = $this->request->getPost(); $sanitizedData = $this->sanitized($postData, $nullIfEmpty); // JJO $sanitizedData['user_updated_id'] = auth()->user()->id; $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($this->canValidate()) : try { $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); } catch (\Exception $e) { $noException = false; $this->dealWithException($e); } else: $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Pedidos.albaran'))]); $this->session->setFlashdata('formErrors', $this->model->errors()); endif; $albaranEntity->fill($sanitizedData); endif; if ($noException && $successfulResult) : $id = $albaranEntity->id ?? $id; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.'; $data = [ 'error' => 0, $csrfTokenName => $newTokenHash ]; return $this->respond($data); endif; // $noException && $successfulResult endif; // ($requestMethod === 'post') $data = [ 'error' => 1, $csrfTokenName => $newTokenHash ]; return $this->respond($data); } else { return $this->failUnauthorized('Invalid request', 403); } } }