/** * Get a field of given entity. * * @param BaseForm $entity * @param string $fieldId * * @return \Kalnoy\Cruddy\Contracts\Field */ protected function findField($entity, $fieldId) { $field = $entity->getFields()->get($fieldId); if (!$field) { throw new RuntimeException("The field [{$entity->getId()}.{$fieldId}] is not defined."); } return $field; }
/** * @param BaseForm $form * @param BaseFormData $data * * @return \Illuminate\Http\JsonResponse */ protected function validateAndSave(BaseForm $form, BaseFormData $data) { $data->validate(); $model = $data->save(); return new JsonResponse($form->extract($model)); }
/** * Process the data. * * @param array $data */ protected function process(array $data) { $this->input = $this->form->getFields()->process($data); }
/** * @return string */ public function getFullyQualifiedId() { return $this->entity->getId() . '.' . $this->id; }
/** * @return array */ public function toArray() { $model = new $this->model(); return ['defaults' => $this->defaultAttributes(), 'primary_key' => $model->getKeyName(), 'soft_deleting' => false, 'order_by' => $this->defaultOrder, 'columns' => $this->getColumns()->toArray(), 'filters' => $this->getFilters()->toArray()] + parent::toArray(); }