/**
  * @param FieldRepository $repository
  * @param int         $fieldId
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postEdit(FieldRepository $repository, $fieldId)
 {
     $repository->validateOnUpdate($fieldId, $this->request);
     /** @var FieldInterface $field */
     $field = $repository->update($fieldId, $this->request->all());
     return $this->smartRedirect([$field->getId()])->with('success', trans($this->wrapNamespace('core.messages.field.updated'), ['title' => $field->getName()]));
 }
 /**
  * @param FieldRepository $repository
  *
  * @throws \KodiCMS\Datasource\Exceptions\FieldException
  */
 public function onCreated(FieldRepository $repository)
 {
     if (!is_null($this->getRelatedFieldId())) {
         return;
     }
     $data = ['section_id' => $this->getRelatedSectionId(), 'is_system' => 1, 'name' => $this->getSection()->getName(), 'related_section_id' => $this->getSection()->getId(), 'related_field_id' => $this->getId()];
     if ($this->getRelatedSectionId() == $this->section_id) {
         $data['settings']['is_editable'] = false;
     }
     $relatedField = null;
     switch ($this->getRelationType()) {
         case static::ONE_TO_ONE:
             $relatedField = $repository->create(array_merge(['type' => 'belongs_to', 'key' => $this->getRelatedDBKey()], $data));
             break;
         case static::ONE_TO_MANY:
             $relatedField = $repository->create(array_merge(['type' => 'has_many', 'key' => $this->getDBKey() . '_has_many'], $data));
             break;
     }
     if (!is_null($relatedField)) {
         $this->update(['related_field_id' => $relatedField->getId()]);
     }
 }
 /**
  * @param FieldRepository $repository
  *
  * @throws \KodiCMS\Datasource\Exceptions\FieldException
  */
 public function onCreated(FieldRepository $repository)
 {
     if (!is_null($this->getRelatedFieldId())) {
         return;
     }
     $relatedField = $repository->create(['type' => 'belongs_to', 'section_id' => $this->getRelatedSectionId(), 'is_system' => 1, 'key' => $this->getRelatedDBKey(), 'name' => $this->getSection()->getName(), 'related_section_id' => $this->getSection()->getId(), 'related_field_id' => $this->getId()]);
     if (!is_null($relatedField)) {
         $this->update(['related_field_id' => $relatedField->getId()]);
     }
 }
 /**
  * @param FieldRepository $repository
  *
  * @throws \KodiCMS\Datasource\Exceptions\FieldException
  */
 public function onCreated(FieldRepository $repository)
 {
     if (!is_null($this->getRelatedFieldId())) {
         return;
     }
     $data = ['section_id' => $this->getRelatedSectionId(), 'is_system' => 1, 'name' => $this->getSection()->getName(), 'related_section_id' => $this->getSection()->getId(), 'related_field_id' => $this->getId()];
     if ($this->getRelatedSectionId() == $this->section_id) {
         $data['settings']['is_editable'] = false;
     }
     $relatedField = $repository->create(array_merge(['type' => 'belongs_to', 'key' => $this->getDBKey() . '_belongs_to'], $data));
     if (!is_null($relatedField)) {
         $this->update(['related_field_id' => $relatedField->getId()]);
     }
 }
 /**
  * @param FieldRepository $repository
  */
 public function setInvisible(FieldRepository $repository)
 {
     $fieldId = $this->getRequiredParameter('field_id');
     $repository->updateVisible($fieldId, false);
     $this->setContent(true);
 }
 /**
  * @param FieldRepository $repository
  *
  * @throws \KodiCMS\Datasource\Exceptions\FieldException
  */
 public function onCreated(FieldRepository $repository)
 {
     if (!is_null($this->getRelatedFieldId())) {
         return;
     }
     $relatedTable = 'ds_mtm_' . uniqid();
     $relatedField = null;
     if (is_null($this->relatedFieldKey) or is_null($relatedSection = $this->getRelatedSection()) or is_null($relatedField = $relatedSection->getFields()->getByKey($this->relatedFieldKey))) {
         $relatedField = $repository->create(['type' => $this->relatedFieldType, 'section_id' => $this->getRelatedSectionId(), 'is_system' => 1, 'key' => $this->getRelatedDBKey(), 'name' => $this->getSection()->getName(), 'related_section_id' => $this->getSection()->getId(), 'related_field_id' => $this->getId(), 'related_table' => $relatedTable, 'settings' => $this->getSettings()]);
     }
     if (!is_null($relatedField)) {
         Schema::create($relatedTable, function ($table) use($relatedField, $relatedTable) {
             $table->integer($this->getDBKey());
             $table->integer($relatedField->getDBKey());
             $table->primary([$this->getDBKey(), $relatedField->getDBKey()], $relatedTable);
         });
         $this->update(['related_field_id' => $relatedField->getId(), 'related_table' => $relatedTable]);
     }
 }