Skip to content

Commit

Permalink
Merge pull request #5 from alrik11es/main
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
georgechitechi authored Feb 4, 2023
2 parents 0c270b6 + c5eb53a commit d16339c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ composer.lock
docs
vendor
coverage
node_modules
node_modules
.idea
25 changes: 13 additions & 12 deletions src/Commands/LivewireGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ abstract class LivewireGeneratorCommand extends Command
* Controller Namespace.
* @var string
*/
protected $controllerNamespace = 'App\Http\Controllers';
protected $controllerNamespace = 'App\Http\Controllers';
/**
* Controller Namespace.
* @var string
Expand Down Expand Up @@ -133,6 +133,7 @@ protected function makeDirectory($path)
*/
protected function write($path, $content)
{
$this->files->makeDirectory(dirname($path), 0755, true, true);
$this->files->put($path, $content);
}

Expand Down Expand Up @@ -181,11 +182,11 @@ private function _getSpace($no = 1)
protected function _getMigrationPath($name)
{
return base_path("database/migrations/". date('Y-m-d_His') ."_create_". Str::lower(Str::plural($name)) ."_table.php");
}
}
protected function _getFactoryPath($name)
{
return base_path("database/factories/{$name}Factory.php");
}
}

/**
* @param $name
Expand Down Expand Up @@ -337,7 +338,7 @@ protected function buildLayout(): void
protected function getColumns()
{
if (empty($this->tableColumns)) {
$this->tableColumns = DB::select('SHOW COLUMNS FROM ' . $this->table);
$this->tableColumns = DB::select('SHOW COLUMNS FROM `' . $this->table.'`');
}

return $this->tableColumns;
Expand All @@ -358,7 +359,7 @@ protected function getFilteredColumns()
return array_filter($columns, function ($value) use ($unwanted) {
return !in_array($value, $unwanted);
});
}
}

/**
* Make model attributes/replacements.
Expand Down Expand Up @@ -421,7 +422,7 @@ protected function modelReplacements()

// CSV format
return implode(', ', $filterColumns);
};
};

$resetfields = function () {

Expand All @@ -436,8 +437,8 @@ protected function modelReplacements()

// CSV format
return implode('', $filterColumns);
};
};

$addfields = function () {

/** @var array $filterColumns Exclude the unwanted columns */
Expand All @@ -450,8 +451,8 @@ protected function modelReplacements()

// CSV format
return implode(',', $filterColumns);
};
};

$keyWord = function () {

/** @var array $filterColumns Exclude the unwanted columns */
Expand All @@ -464,7 +465,7 @@ protected function modelReplacements()

// CSV format
return implode('', $filterColumns);
};
};

$factoryfields = function () {

Expand All @@ -479,7 +480,7 @@ protected function modelReplacements()
// CSV format
return implode('', $filterColumns);
};

$editfields = function () {

/** @var array $filterColumns Exclude the unwanted columns */
Expand Down
12 changes: 6 additions & 6 deletions src/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ private function _getTableRelations()
{
$db = DB::getDatabaseName();
$sql = <<<SQL
SELECT TABLE_NAME ref_table, COLUMN_NAME foreign_key, REFERENCED_COLUMN_NAME local_key, '1' ref
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
SELECT TABLE_NAME ref_table, COLUMN_NAME foreign_key, REFERENCED_COLUMN_NAME local_key, '1' ref
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE REFERENCED_TABLE_NAME = '$this->table' AND TABLE_SCHEMA = '$db'
UNION
SELECT REFERENCED_TABLE_NAME ref_table, REFERENCED_COLUMN_NAME foreign_key, COLUMN_NAME local_key, '0' ref
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE TABLE_NAME = '$this->table' AND TABLE_SCHEMA = '$db' AND REFERENCED_TABLE_NAME IS NOT NULL
SELECT REFERENCED_TABLE_NAME ref_table, REFERENCED_COLUMN_NAME foreign_key, COLUMN_NAME local_key, '0' ref
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE TABLE_NAME = '$this->table' AND TABLE_SCHEMA = '$db' AND REFERENCED_TABLE_NAME IS NOT NULL
ORDER BY ref_table ASC
SQL;
Expand All @@ -135,6 +135,6 @@ private function _getTableRelations()
*/
private function _getTableKeys($table)
{
return DB::select("SHOW KEYS FROM {$table}");
return DB::select("SHOW KEYS FROM `{$table}`");
}
}

0 comments on commit d16339c

Please sign in to comment.