/** * 验证方法 * @throws \HttpRequestException */ public function validate() { foreach ($this->getKform()->getFormFields() as $formField) { if ($formField instanceof FormField) { $formField->setValue(Input::get($formField->getFieldName()), $this); } } if (!$this->getKform()->isPassed()) { $errors = $this->getKform()->getErrors(); if ($this->ajax() || $this->wantsJson()) { $response = new APIJsonResponse(); $error = new FailedValidtionError(); $error->setErrorContext($errors); $response->pushError($error); throw new HttpResponseException($response->getResponse()); } else { $messenger = new KMessenger(); foreach ($this->getKform()->getFormFields() as $formField) { foreach ($formField->getErrors() as $error) { $messenger->push($error, KMessenger::ERROR); } } $view = $this->directlyErrorView(); if ($view instanceof View) { $response = \Response::make($view); } else { $response = $this->redirectBackResponse(); } throw new HttpResponseException($response); } } }
/** * 处理恢复请求 * @return \Illuminate\Http\RedirectResponse */ public function postRestore() { $id = Input::get('id'); $result = false; if ($id) { if (!is_array($id)) { $id = [$id]; } if (!empty($id)) { $result = $this->queryScope()->onlyTrashed()->whereIn('id', $id)->restore(); } } $messenger = new KMessenger(); if ($result) { $messenger->push('成功恢复了一个' . static::$name, KMessenger::SUCCESS); } else { $messenger->push('恢复' . static::$name . '失败', KMessenger::ERROR); } return $this->redirectToMethod('getIndex'); }