Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * @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));
 }
Example #3
0
 /**
  * Process the data.
  *
  * @param array $data
  */
 protected function process(array $data)
 {
     $this->input = $this->form->getFields()->process($data);
 }
Example #4
0
 /**
  * @return string
  */
 public function getFullyQualifiedId()
 {
     return $this->entity->getId() . '.' . $this->id;
 }
Example #5
0
 /**
  * @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();
 }