Skip to content

Commit 7b6a8e2

Browse files
author
Nathan E
committed
fix: add support for enum datatypes
1 parent cfb577f commit 7b6a8e2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Generators/FactoryGenerator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ protected function buildDefinition(Model $model)
7979
$faker = $this->fakerData($column->name()) ?? $this->fakerDataType($column->dataType());
8080
$definition .= '$faker->' . $faker;
8181
$definition .= ',' . PHP_EOL;
82+
83+
if ($column->dataType() === 'enum' and !empty($column->attributes())) {
84+
$definition = str_replace("/** attributes **/", json_encode($column->attributes()), $definition);
85+
}
8286
}
8387
}
8488

@@ -143,7 +147,8 @@ protected function fakerDataType(string $type)
143147
'decimal' => 'randomFloat()',
144148
'float' => 'randomFloat()',
145149
'longtext' => 'text',
146-
'boolean' => 'boolean'
150+
'boolean' => 'boolean',
151+
'enum' => 'randomElement(/** attributes **/)',
147152
];
148153

149154
return $fakeableTypes[$type] ?? null;

0 commit comments

Comments
 (0)