feat: implement module generator with automated migration, model, and view creation
This commit is contained in:
@@ -54,6 +54,7 @@ class ModuleGeneratorController extends Controller
|
||||
case 'decimal': $dbType = 'decimal'; break;
|
||||
case 'date': $dbType = 'date'; break;
|
||||
case 'datetime': $dbType = 'dateTime'; break;
|
||||
case 'time': $dbType = 'time'; break;
|
||||
case 'long-text': $dbType = 'longText'; break;
|
||||
case 'boolean': $dbType = 'boolean'; break;
|
||||
default: $dbType = 'string'; break;
|
||||
@@ -90,23 +91,21 @@ class ModuleGeneratorController extends Controller
|
||||
if (File::exists($templatePath)) {
|
||||
$templateContent = File::get($templatePath);
|
||||
|
||||
// Simple replacements in template
|
||||
$templateContent = str_replace('use App\Models\RadiographicTest;', "use App\Models\\{$modelName};", $templateContent);
|
||||
$templateContent = str_replace('$title = "Radiographic Test";', "\$title = \"{$title}\";", $templateContent);
|
||||
$templateContent = str_replace('$tableName = "radiographic_tests";', "\$tableName = \"{$tableName}\";", $templateContent);
|
||||
// Placeholder replacements
|
||||
$templateContent = str_replace('[[MODEL_NAME]]', $modelName, $templateContent);
|
||||
$templateContent = str_replace('[[TITLE]]', $title, $templateContent);
|
||||
$templateContent = str_replace('[[TABLE_NAME]]', $tableName, $templateContent);
|
||||
|
||||
// Generate relationDatas
|
||||
$relationDatasCode = "\$relationDatas = [\n";
|
||||
$relationDatasCode = "[\n";
|
||||
foreach ($request->columns as $column) {
|
||||
$colName = Str::snake($column['name']);
|
||||
$colType = $column['type'];
|
||||
$relationDatasCode .= " '{$colName}' => [\n 'type' => '{$colType}',\n ],\n";
|
||||
}
|
||||
$relationDatasCode .= "];";
|
||||
$relationDatasCode .= "]";
|
||||
|
||||
// Replace the hardcoded relationDatas in template
|
||||
$pattern = '/\$relationDatas = \[.*?\];/s';
|
||||
$templateContent = preg_replace($pattern, $relationDatasCode, $templateContent);
|
||||
$templateContent = str_replace('[[RELATION_DATAS]]', $relationDatasCode, $templateContent);
|
||||
|
||||
File::put($viewPath, $templateContent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user