feat: implement module generator with automated migration, model, and view creation

This commit is contained in:
Ümit Tunç
2026-04-28 23:45:00 +03:00
parent afc047b0bb
commit 74901dc3c6
7 changed files with 125 additions and 156 deletions
@@ -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);
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Products extends Model
{
use SoftDeletes;
protected $table = 'products';
protected $guarded = [];
}