Skip to content

Commit

Permalink
fix the key
Browse files Browse the repository at this point in the history
  • Loading branch information
celia514 committed Jul 25, 2024
1 parent ef12493 commit 87d1e98
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Resources/ScaffoldResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public static function form(Form $form): Form
->default('')
->options([
'' => 'NULL',
'PRI' => 'Primary',
'UNI' => 'Unique',
'MUL' => 'Index',
'primary' => 'Primary',
'unique' => 'Unique',
'index' => 'Index',
])
->default(fn ($record) => $record['key'] ?? ''),
Forms\Components\TextInput::make('default')
Expand Down Expand Up @@ -151,6 +151,12 @@ public static function getTableColumns($tableName)
'macaddress' => 'macAddress',
];

$keyMapping = [
'PRI' => 'primary',
'UNI' => 'unique',
'MUL' => 'index',
];

foreach ($columns as $column) {
if ($column->Key === 'PRI') {
continue;
Expand All @@ -159,13 +165,16 @@ public static function getTableColumns($tableName)
$type = preg_replace('/\(.+\)/', '', $column->Type);
$type = preg_split('/\s+/', $type)[0];

$key = $column->Key;

$translatedType = $typeMapping[$type] ?? $type;
$translatedKey = $keyMapping[$key] ?? $key;

$columnDetails[] = [
'name' => $column->Field,
'type' => $translatedType,
'nullable' => $column->Null === 'YES',
'key' => $column->Key,
'key' => $translatedKey,
'default' => $column->Default,
'comment' => '',
];
Expand Down

0 comments on commit 87d1e98

Please sign in to comment.