Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
celia514 committed Jul 25, 2024
1 parent b8cef00 commit c6f8ab8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Resources/ScaffoldResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,27 @@ private static function generateColumnDefinition(array $column): string

public static function overwriteModelFile($filePath, $data)
{
$column = self::getColumn($data);

if (file_exists($filePath)) {
$content = file_get_contents($filePath);
$chooseTable = <<<EOD
use HasFactory;
protected \$table = '{$data['Table Name']}';
protected \$fillable = $column
EOD;

$content = preg_replace('/use HasFactory;/s', $chooseTable, $content);
file_put_contents($filePath, $content);
}
}

public static function getColumn($data)
{
$fields = [];
foreach ($data['Table'] as $column) {
$fields[] = "{$column['name']}";
}
return "['" . implode("','", $fields) . "']";
}
}

0 comments on commit c6f8ab8

Please sign in to comment.