From b087636212eede9d2a266278c7277c13057de5cc Mon Sep 17 00:00:00 2001 From: Oscar Fernandez Date: Fri, 28 Aug 2020 21:03:59 -0300 Subject: [PATCH] Fix text type and timestamps precision --- .../Generators/FieldGenerator.php | 4 +-- .../MigrationsGenerator/Syntax/AddToTable.php | 26 +++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/OscarAFDev/MigrationsGenerator/Generators/FieldGenerator.php b/src/OscarAFDev/MigrationsGenerator/Generators/FieldGenerator.php index 5a56e52..0d0c798 100644 --- a/src/OscarAFDev/MigrationsGenerator/Generators/FieldGenerator.php +++ b/src/OscarAFDev/MigrationsGenerator/Generators/FieldGenerator.php @@ -131,10 +131,10 @@ protected function getFields($columns, IndexGenerator $indexGenerator) $type = 'softDeletes'; $name = ''; } elseif ($name == 'created_at' and isset($fields['updated_at'])) { - $fields['updated_at'] = ['field' => '', 'type' => 'timestamps']; + $fields['updated_at'] = ['field' => '', 'type' => 'timestamps', 'args' => $column->getPrecision()]; continue; } elseif ($name == 'updated_at' and isset($fields['created_at'])) { - $fields['created_at'] = ['field' => '', 'type' => 'timestamps']; + $fields['created_at'] = ['field' => '', 'type' => 'timestamps', 'args' => $column->getPrecision()]; continue; } } elseif (in_array($type, ['decimal', 'float', 'double'])) { diff --git a/src/OscarAFDev/MigrationsGenerator/Syntax/AddToTable.php b/src/OscarAFDev/MigrationsGenerator/Syntax/AddToTable.php index fbc0ffa..4380de1 100644 --- a/src/OscarAFDev/MigrationsGenerator/Syntax/AddToTable.php +++ b/src/OscarAFDev/MigrationsGenerator/Syntax/AddToTable.php @@ -34,14 +34,24 @@ protected function getItem(array $field) // If we have args, then it needs // to be formatted a bit differently - if (isset($field['args'])) { - $output = sprintf( - "\$table->%s(%s, %s)", - $type, - $property, - $field['args'] - ); - } + if (isset($field['args']) && $type !== 'text') + { + if ($property == '' || $property == null) { + $output = sprintf( + "\$table->%s(%s)", + $type, + $field['args'] + ); + } + else { + $output = sprintf( + "\$table->%s('%s', %s)", + $type, + $property, + $field['args'] + ); + } + } if (isset($field['decorators'])) { $output .= $this->addDecorators( $field['decorators'] ); }