/** * Construct the syntax to add a column. * * @param Field $field * @return string */ private function addColumn(Field $field) { $syntax = ''; if (!$this->onlyForeign) { $syntax = sprintf("\$table->%s('%s')", $field->getType(), $field->getName()); // If there are arguments for the schema type, like decimal('amount', 5, 2) // then we have to remember to work those in. if ($field->hasArguments()) { $syntax = substr($syntax, 0, -1) . ', '; $syntax .= implode(', ', $field->getArguments()) . ')'; } if ($field->isUnique()) { $syntax .= "->unique()"; } if ($field->isNullable()) { $syntax .= "->nullable()"; } if ($field->isUnsigned()) { $syntax .= "->unsigned()"; } if ($field->hasDefault()) { $syntax .= "->default({$field->getDefault()})"; } $syntax .= ';'; if ($field->isIndex()) { $syntax .= "\n" . str_repeat(' ', 12) . "\$table->index('{$field->getName()}');"; } } if ($field->hasForeign() && ($this->generateForeign || $this->onlyForeign)) { $foreign = $field->getForeign(); $syntax .= "\n" . str_repeat(' ', 12) . sprintf("\$table->foreign('%s')->references('%s')->on('%s');", $this->getForeignKeyName($field), $foreign->getReferences(), $foreign->getOn()); } return $syntax; }
public static function isEnum(Field $field) { return in_array($field->getType(), ['enum']); }