protected function getFieldAccessorValue(Field $field, $view)
    {
        $fieldAccessor = sprintf('$%s->%s', $this->getSingularVariable($this->modelName), $field->name);

        if ($field->hasForeignRelation() && $field->isOnView($view)) {
            $relation = $field->getForeignRelation();
            if (Helpers::isNewerThanOrEqualTo('5.5')) {
                $fieldAccessor = sprintf('optional($%s->%s)->%s', $this->getSingularVariable($this->modelName), $relation->name, $relation->getField());
            } else {
                $fieldAccessor = sprintf('$%s->%s->%s', $this->getSingularVariable($this->modelName), $relation->name, $relation->getField());
                $fieldAccessor = sprintf(" isset(%s) ? %s : '' ", $fieldAccessor, $fieldAccessor);
            }
        }

        if ($field->isBoolean()) {
            return sprintf("(%s) ? '%s' : '%s'", $fieldAccessor, $field->getTrueBooleanOption()->text, $field->getFalseBooleanOption()->text);
        }

        if ($field->isMultipleAnswers()) {
            return sprintf("implode('%s', %s)", $field->optionsDelimiter, $fieldAccessor);
        }

        return $fieldAccessor;
    }
protected function getFieldAccessorValue(Field $field, $view)
    {
        $fieldAccessor = sprintf('$%s->%s', $this->getSingularVariable($this->modelName), $field->name);

        if ($field->hasForeignRelation() && $field->isOnView($view)) {
            $relation = $field->getForeignRelation();
            if (Helpers::isNewerThanOrEqualTo('5.5')) {
                $fieldAccessor = sprintf('optional($%s->%s)->%s', $this->getSingularVariable($this->modelName), $relation->name, $relation->getField());
            } else {
                $fieldAccessor = sprintf('$%s->%s->%s', $this->getSingularVariable($this->modelName), $relation->name, $relation->getField());
                $fieldAccessor = sprintf(" isset(%s) ? %s : '' ", $fieldAccessor, $fieldAccessor);
            }
        }

        if ($field->isBoolean()) {
            return sprintf("(%s) ? '%s' : '%s'", $fieldAccessor, $field->getTrueBooleanOption()->text, $field->getFalseBooleanOption()->text);
        }

        if ($field->isMultipleAnswers()) {
            return sprintf("implode('%s', %s)", $field->optionsDelimiter, $fieldAccessor);
        }

        return $fieldAccessor;
    }
protected function getFieldAccessorValue ( Field $ field , $ view ) { $ fieldAccessor = sprintf ( '$%s->%s' , $ this -> getSingularVariable ( $ this -> modelName ) , $ field -> name ) ; if ( $ field -> hasForeignRelation ( ) && $ field -> isOnView ( $ view ) ) { $ relation = $ field -> getForeignRelation ( ) ; if ( Helpers :: isNewerThanOrEqualTo ( '5.5' ) ) { $ fieldAccessor = sprintf ( 'optional($%s->%s)->%s' , $ this -> getSingularVariable ( $ this -> modelName ) , $ relation -> name , $ relation -> getField ( ) ) ; } else { $ fieldAccessor = sprintf ( '$%s->%s->%s' , $ this -> getSingularVariable ( $ this -> modelName ) , $ relation -> name , $ relation -> getField ( ) ) ; $ fieldAccessor = sprintf ( " isset(%s) ? %s : '' " , $ fieldAccessor , $ fieldAccessor ) ; } } if ( $ field -> isBoolean ( ) ) { return sprintf ( "(%s) ? '%s' : '%s'" , $ fieldAccessor , $ field -> getTrueBooleanOption ( ) -> text , $ field -> getFalseBooleanOption ( ) -> text ) ; } if ( $ field -> isMultipleAnswers ( ) ) { return sprintf ( "implode('%s', %s)" , $ field -> optionsDelimiter , $ fieldAccessor ) ; } return $ fieldAccessor ; }
Gets a value accessor for the field.

@param CrestApps\CodeGenerator\Models\Field $field
@param string $view

@return string
Gets a value accessor for the field .