/**
  * @param FieldInterface $field
  *
  * @return $this
  */
 public function add(FieldInterface $field)
 {
     if ($field->exists) {
         $field->initFilterType();
     }
     $this->fields->put($field->getDBKey(), $field);
     return $this;
 }
 /**
  * @param FieldInterface $field
  *
  * @return bool
  */
 public function dropSectionTableField(FieldInterface $field)
 {
     if (!$field->hasDatabaseColumn()) {
         return true;
     }
     $section = $field->getSection();
     if (!Schema::hasColumn($section->getSectionTableName(), $field->getDBKey())) {
         return false;
     }
     Schema::table($section->getSectionTableName(), function ($table) use($field) {
         $field->onDatabaseDrop($table);
     });
     return true;
 }
 /**
  * @param DocumentInterface   $document
  * @param SectionInterface    $relatedSection
  * @param FieldInterface|null $relatedField
  *
  * @return \Illuminate\Database\Eloquent\Relations\ManyToMany
  */
 public function getDocumentRelation(DocumentInterface $document, SectionInterface $relatedSection = null, FieldInterface $relatedField = null)
 {
     $relatedDocument = $relatedSection->getEmptyDocument();
     $builder = $relatedDocument->newQuery();
     return new BelongsToManyRelation($builder, $document, $this->getRelatedTable(), $this->getDBKey(), $relatedField->getDBKey(), $this->getRelationName());
 }