public static function migration()
{
return ['text' => 'string("$FIELDNAME$")', 'email' => 'string("$FIELDNAME$")', 'textarea' => 'text("$FIELDNAME$")', 'radio' => 'string("$FIELDNAME$")', 'checkbox' => 'tinyInteger("$FIELDNAME$")->default($STATE$)', 'date' => 'date("$FIELDNAME$")', 'datetime' => 'dateTime("$FIELDNAME$")', 'relationship' => 'integer("$RELATIONSHIP$_id")->references("id")->on("$RELATIONSHIP$")', 'file' => 'string("$FIELDNAME$")', 'photo' => 'string("$FIELDNAME$")', 'password' => 'string("$FIELDNAME$")', 'money' => 'decimal("$FIELDNAME$", 15, 2)', 'enum' => 'enum("$FIELDNAME$", [$VALUES$])'];
}
/** * Build migration fields * @return string */ 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 $fields .= '$table->' . $migrationLine . ";\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; }