diff --git a/src/DatabaseParsers/MysqlParser.php b/src/DatabaseParsers/MysqlParser.php index 1f75674..0d11977 100644 --- a/src/DatabaseParsers/MysqlParser.php +++ b/src/DatabaseParsers/MysqlParser.php @@ -110,13 +110,13 @@ protected function getRawIndexes() { $result = DB::select( 'SELECT - INDEX_NAME AS name - ,COUNT(1) AS TotalColumns - ,GROUP_CONCAT(DISTINCT COLUMN_NAME ORDER BY SEQ_IN_INDEX ASC SEPARATOR \'|||\') AS columns - FROM INFORMATION_SCHEMA.STATISTICS AS s - WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ? - GROUP BY INDEX_NAME - HAVING COUNT(1) > 1;', + INDEX_NAME AS name + ,COUNT(1) AS TotalColumns + ,GROUP_CONCAT(DISTINCT COLUMN_NAME ORDER BY SEQ_IN_INDEX ASC SEPARATOR \'|||\') AS columns + FROM INFORMATION_SCHEMA.STATISTICS AS s + WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ? + GROUP BY INDEX_NAME + HAVING COUNT(1) > 1;', [$this->tableName, $this->databaseName] ); @@ -247,6 +247,9 @@ protected function getTransfredFields(array $columns) $collection = []; foreach ($columns as $column) { + // While constructing the array for each field + // there is no need to set translations for options + // or even labels. This step is handled using the FieldTransformer $properties['name'] = $column->COLUMN_NAME; $properties['is-nullable'] = ($column->IS_NULLABLE == 'YES'); $properties['data-value'] = $column->COLUMN_DEFAULT; @@ -262,7 +265,7 @@ protected function getTransfredFields(array $columns) $constraint = $this->getForeignConstraint($column->COLUMN_NAME); - $properties['foreign-constraint'] = is_null($constraint) ? null : $constraint->toArray(); + $properties['foreign-constraint'] = !is_null($constraint) ? $constraint->toArray() : null; if (intval($column->CHARACTER_MAXIMUM_LENGTH) > 255 || in_array($column->DATA_TYPE, $this->largeDataTypes)) { @@ -273,6 +276,9 @@ protected function getTransfredFields(array $columns) } $localeGroup = Helpers::makeLocaleGroup($this->tableName); $fields = FieldTransformer::fromArray($collection, $localeGroup, $this->languages); + + // At this point we constructed the fields collection with the default html-type + // We need to set the html-type using the config::getEloquentToHtmlMap() setting $this->setHtmlType($fields); return $fields; diff --git a/src/DatabaseParsers/ParserBase.php b/src/DatabaseParsers/ParserBase.php index 9413f47..66d124a 100644 --- a/src/DatabaseParsers/ParserBase.php +++ b/src/DatabaseParsers/ParserBase.php @@ -29,16 +29,6 @@ abstract class ParserBase 'deleted_at', ]; - /** - * The default boolean options to use. - * - * @var array - */ - protected $booleanOptions = [ - '0' => 'No', - '1' => 'Yes', - ]; - /** * The table name. * @@ -180,13 +170,15 @@ protected function getHtmlType($type) * @param CrestApps\CodeGenerator\Models\Field $field * @param string $type * - * @return string + * @return $this */ protected function setHtmlType(array &$fields) { foreach ($fields as $field) { $field->htmlType = $this->getHtmlType($field->getEloquentDataMethod()); } + + return $this; } /** @@ -210,7 +202,21 @@ protected function getModelName($tableName) { $modelName = ResourceMapper::pluckFirst($tableName, 'table-name', 'model-name'); - return $modelName ?: ucfirst(camel_case(Str::singular($tableName))); + return $modelName ?: $this->makeModelName($tableName); + } + + /** + * Make a model name from the giving table name + * + * @param string $tableName + * + * @return string + */ + protected function makeModelName($tableName) + { + $name = Str::singular($tableName); + + return ucfirst(camel_case($name)); } /**