diff src/Generator/Factory/FactoryGenerator.php @ 36:76584181267a ls_dev_2025_09

Got factories working in a basic way, not sure how complex tables will handle it though
author Luka Sitas <sitas.luka.97@gmail.com>
date Sat, 20 Sep 2025 17:14:29 -0400
parents 55d2e5c5dad9
children b5c6ebd33547
line wrap: on
line diff
--- a/src/Generator/Factory/FactoryGenerator.php	Thu Sep 11 21:25:51 2025 -0400
+++ b/src/Generator/Factory/FactoryGenerator.php	Sat Sep 20 17:14:29 2025 -0400
@@ -91,33 +91,34 @@
 
 		protected function renderColumns() {
         $insert = '';
+				$values = [];
         foreach ($this->get_columns() as $column) {
             if (in_array($column['name'], $this->columns_to_ignore)) {
                 continue;
             }
 
-
             $type = $column['type_name'];
 						$nullable = ($column['nullable'] ? '->optional($weight = 0.5)' : '' );
+						$value = 'fake()' . $nullable;
 						$name = $column['name'];
 
             // Get the expected header name
             $replacements = [
-                '{{value}}' => 'fake()' . $nullable . '->text()',
+                '{{value}}' => $value . '->text()',
                 '{{column_name}}' => $name,
             ];
 
             // date
             if (in_array($type, ['date'])) {
-                $replacements['{{value}}'] = 'fake()' . $nullable . '->date()';
+                $replacements['{{value}}'] = $value . '->date()';
             }
             // time
             if (in_array($type, ['timestamp'])) {
-                $replacements['{{value}}'] = 'fake()' . $nullable . '->timestamp()';
+                $replacements['{{value}}'] = $value . '->timestamp()';
             }
             // checkbox
             if (in_array($type, ['tinyint'])) {
-                $replacements['{{value}}'] = 'fake()' . $nullable . '->boolean()';
+                $replacements['{{value}}'] = $value . '->boolean()';
             }
             // select
             elseif (in_array($type, ['bigint']) && array_key_exists($name, $selects)) {
@@ -125,14 +126,17 @@
                 $replacements['{{value}}'] = '{{ $item->'.Str::singular($selects[$name]).'?->name ?? "" }}';
             }
             // bigint, float
-            elseif (in_array($type, ['bigint', 'float', 'int'])) {
-                $replacements['{{valueClass}}'] .= ' text-start';
+            elseif (in_array($type, ['bigint', 'int'])) {
+                $replacements['{{value}}'] = $value . '->randomNumber()';
+						}
+            elseif (in_array($type, ['float'])) {
+                $replacements['{{value}}'] = $value . '->randomFloat()';
             } else {
                 // text area
                 // varchar, , etc
             }
 
-            $snippet = $this->getSnippet('index/value');
+            $snippet = $this->getSnippet('value');
             // Replace placeholders with actual values
             $values[] = str_replace(
                 array_keys($replacements),
@@ -140,21 +144,9 @@
                 $snippet
             );
 
-
-
-						$tableName = $this->getCurrentTable();
-						$value = 'value'; // TODO: this should be determined based on column type
-						$columnName = $column['name'];
-
 						// Replace placeholders with actual values
-        		$string = str_replace(
-        		    ['{{value}}', '{{columnName}}'],
-        		    [$value, $columnName],
-        		    $snippet
-        		);
-            $insert .= sprintf("%s", $string);
         }
-				dd('done');
+				$insert = implode("\n", $values);
 
 				return $insert;
 		}