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