src/Builders/MigrationBuilder.php
private function buildFields()
    {
        $migrationTypes = FieldsDescriber::migration();
        $used           = [];
        $fields         = '$table->increments("id");' . "\r\n";
        foreach ($this->fields as $field) {
            // Check if there is no duplication for radio and checkbox
            if (!in_array($field->title, $used)) {
                // Generate our migration line
                $migrationLine = str_replace([
                    '$FIELDNAME$',
                    '$STATE$',
                    '$RELATIONSHIP$',
                ], [
                    $field->title,
                    $field->default == 'true' ? 1 : 0,
                    $field->relationship_name
                ], $migrationTypes[$field->type]);
                $fields .= '            '; // Add formatting space to the migration
                if ($field->type == 'enum') {
                    $values      = '';
                    $field->enum = explode(',', $field->enum);
                    foreach ($field->enum as $val) {
                        // Remove first whitespace
                        if (strpos(substr($val, 0, 1), ' ') !== false) {
                            $len = strlen($val);
                            $val = substr($val, 1, $len);
                        }
                        $values .= '"' . $val . '"';
                        if ($val != last($field->enum)) {
                            $values .= ', ';
                        }
                    }
                    $migrationLine = str_replace('$VALUES$', $values, $migrationLine);
                }
                $fields .= '$table->' . $migrationLine;
                if (in_array($field->validation, FieldsDescriber::nullables())) {
                    $fields .= '->nullable()';
                }
                $fields .= ";\r\n";
                if ($field->type == 'relationship') {
                    $used[$field->relationship_name] = $field->relationship_name;
                } else {
                    $used[$field->title] = $field->title;
                }
            }
        }
        $fields .= '            '; // Add formatting space to the migration
        $fields .= '$table->timestamps();';
        if ($this->soft == 1) {
            $fields .= "\r\n";
            $fields .= '            '; // Add formatting space to the migration
            $fields .= '$table->softDeletes();';
        }

        return $fields;
    }
private function buildFields()
    {
        $migrationTypes = FieldsDescriber::migration();
        $used           = [];
        $fields         = '$table->increments("id");' . "\r\n";
        foreach ($this->fields as $field) {
            // Check if there is no duplication for radio and checkbox
            if (!in_array($field->title, $used)) {
                // Generate our migration line
                $migrationLine = str_replace([
                    '$FIELDNAME$',
                    '$STATE$',
                    '$RELATIONSHIP$',
                ], [
                    $field->title,
                    $field->default == 'true' ? 1 : 0,
                    $field->relationship_name
                ], $migrationTypes[$field->type]);
                $fields .= '            '; // Add formatting space to the migration
                if ($field->type == 'enum') {
                    $values      = '';
                    $field->enum = explode(',', $field->enum);
                    foreach ($field->enum as $val) {
                        // Remove first whitespace
                        if (strpos(substr($val, 0, 1), ' ') !== false) {
                            $len = strlen($val);
                            $val = substr($val, 1, $len);
                        }
                        $values .= '"' . $val . '"';
                        if ($val != last($field->enum)) {
                            $values .= ', ';
                        }
                    }
                    $migrationLine = str_replace('$VALUES$', $values, $migrationLine);
                }
                $fields .= '$table->' . $migrationLine;
                if (in_array($field->validation, FieldsDescriber::nullables())) {
                    $fields .= '->nullable()';
                }
                $fields .= ";\r\n";
                if ($field->type == 'relationship') {
                    $used[$field->relationship_name] = $field->relationship_name;
                } else {
                    $used[$field->title] = $field->title;
                }
            }
        }
        $fields .= '            '; // Add formatting space to the migration
        $fields .= '$table->timestamps();';
        if ($this->soft == 1) {
            $fields .= "\r\n";
            $fields .= '            '; // Add formatting space to the migration
            $fields .= '$table->softDeletes();';
        }

        return $fields;
    }
private function buildFields ( ) { $ migrationTypes = FieldsDescriber :: migration ( ) ; $ used = [ ] ; $ fields = '$table->increments("id");' . "\r\n" ; foreach ( $ this -> fields as $ field ) { // Check if there is no duplication for radio and checkbox if ( ! in_array ( $ field -> title , $ used ) ) { // Generate our migration line $ migrationLine = str_replace ( [ '$FIELDNAME$' , '$STATE$' , '$RELATIONSHIP$' , ] , [ $ field -> title , $ field -> default == 'true' ? 1 : 0 , $ field -> relationship_name ] , $ migrationTypes [ $ field -> type ] ) ; $ fields .= '            ' ; // Add formatting space to the migration if ( $ field -> type == 'enum' ) { $ values = '' ; $ field -> enum = explode ( ',' , $ field -> enum ) ; foreach ( $ field -> enum as $ val ) { // Remove first whitespace if ( strpos ( substr ( $ val , 0 , 1 ) , ' ' ) !== false ) { $ len = strlen ( $ val ) ; $ val = substr ( $ val , 1 , $ len ) ; } $ values .= '"' . $ val . '"' ; if ( $ val != last ( $ field -> enum ) ) { $ values .= ', ' ; } } $ migrationLine = str_replace ( '$VALUES$' , $ values , $ migrationLine ) ; } $ fields .= '$table->' . $ migrationLine ; if ( in_array ( $ field -> validation , FieldsDescriber :: nullables ( ) ) ) { $ fields .= '->nullable()' ; } $ fields .= ";\r\n" ; if ( $ field -> type == 'relationship' ) { $ used [ $ field -> relationship_name ] = $ field -> relationship_name ; } else { $ used [ $ field -> title ] = $ field -> title ; } } } $ fields .= '            ' ; // Add formatting space to the migration $ fields .= '$table->timestamps();' ; if ( $ this -> soft == 1 ) { $ fields .= "\r\n" ; $ fields .= '            ' ; // Add formatting space to the migration $ fields .= '$table->softDeletes();' ; } return $ fields ; }
Build migration fields
@return string
Build migration fields