/**
  * @param Field $field
  */
 public function updated(Field $field)
 {
     if ($field->isAttachedToSection()) {
         FieldManager::updateSectionTableField($field);
     }
     if (method_exists($field, 'onUpdated')) {
         app()->call([$field, 'onUpdated']);
     }
 }
 /**
  * @param Field $field
  */
 public function __construct(Field $field)
 {
     $this->id = $field->getId();
     $this->label = $field->getName();
     $this->tableField = $field->getSection()->getSectionTableName() . '.' . $field->getDBKey();
     if (method_exists($field, 'getFilterOperators')) {
         $this->operators = $field->getFilterOperators();
     }
 }
 /**
  * @param DocumentInterface $document
  *
  * @return array
  */
 protected function fetchDocumentTemplateValues(DocumentInterface $document)
 {
     $relatedSection = $this->getRelatedSection();
     return array_merge(parent::fetchDocumentTemplateValues($document), ['relatedDocument' => $this->getDocumentRelation($document, $relatedSection)->first(), 'relatedSection' => $relatedSection, 'relatedField' => $this->getRelatedField()]);
 }
 protected function initializeFields()
 {
     if (!$this->initializedFields) {
         $fields = Field::where(function ($q) {
             $q->orWhere('section_id', $this->id)->orWhere('related_section_id', $this->id);
         })->with('relatedSection')->get();
         $this->sectionFields = new FieldsCollection($fields->filter(function ($field) {
             return $field->section_id == $this->id;
         }), $this);
         $this->relatedFields = new FieldsCollection($fields->filter(function ($field) {
             return $field->related_section_id == $this->id;
         }), $this);
         $this->initializedFields = true;
     }
 }