/** * Retrieves all Fields for this model * @return array array of Fields objects */ public function getFields() { $fields = array(); if (method_exists($this->model, 'getFields')) { $fields = $this->model->getFields(true); } else { foreach (X2Model::model('Fields')->findAllByAttributes(array('modelName' => ucfirst($this->modelName))) as $fieldModel) { $fields[$fieldModel->fieldName] = $fieldModel; } } return $fields; }
/** * Handle custom ajax response * * @param [type] $request [description] * @param [type] $e [description] * * @return [type] [description] */ protected function handleAjaxException($request, $e) { $response = null; $responseContents = []; // Laravel default validation if ($e instanceof LaravelValidationException && $e->getResponse()) { $errors = $e->validator->messages(); $fields = []; foreach ($errors->getMessages() as $field => $messages) { $fields[$field] = $messages; } $message = $errors->first(); return $this->makeAjaxResponseContent($fields, $message); // Our custom, more simple Validation exception } else { if ($e instanceof ValidationException) { return $this->makeAjaxResponseContent($e->getFields(), $e->getMessage()); // Ajax error message } else { if ($e instanceof AjaxException) { $responseContents = array_merge_recursive($responseContents, $e->getContents()); $responseContents['X_OCTOBER_ERROR_MESSAGE'] = $responseContents['result']; // Smart error code $response = response()->json($responseContents, 406); // Runtime Errors } else { if ($e instanceof \ErrorException) { $message = env('APP_DEBUG', false) ? ajax_dump($e) : 'Whoops, we encountered an error.'; $responseContents['X_OCTOBER_ERROR_MESSAGE'] = $message; $response = response()->json($responseContents, 406); // Catch all } else { $message = env('APP_DEBUG', false) ? ajax_dump($e) : 'Whoops, we encountered an error.'; $responseContents['X_OCTOBER_ERROR_MESSAGE'] = $message; $response = response()->json($responseContents, 406); } } } } return $response; }