comparison src/Generator/Factory/FactoryGenerator.php @ 44:cde7e0f145fa ls_dev_2025_09

merge heads
author Luka Sitas <sitas.luka.97@gmail.com>
date Thu, 12 Nov 2026 21:19:35 -0500
parents 59eb5b4424ca
children
comparison
equal deleted inserted replaced
43:50ca202284d5 44:cde7e0f145fa
117 $value = '$this->faker'; 117 $value = '$this->faker';
118 $nullable = ($column['nullable'] ? '->optional($weight = 0.5)' : ''); 118 $nullable = ($column['nullable'] ? '->optional($weight = 0.5)' : '');
119 119
120 switch ($column['type_name']) { 120 switch ($column['type_name']) {
121 case 'date': 121 case 'date':
122 return "$value$nullable->date()"; 122 return "$value${nullable}->date()";
123 case 'timestamp': 123 case 'timestamp':
124 return "$value$nullable->timestamp()"; 124 return "$value${nullable}->timestamp()";
125 case 'tinyint': 125 case 'tinyint':
126 return "$value$nullable->numberBetween(0,1)"; 126 return "$value${nullable}->numberBetween(0,1)";
127 case 'bigint': 127 case 'bigint':
128 if (isset($relations['belongsTo'][$column['name']])) { 128 if (isset($relations['belongsTo'][$column['name']])) {
129 $related = $this->getNamespacedModel($relations['belongsTo'][$column['name']]['table']); 129 $related = $this->getNamespacedModel($relations['belongsTo'][$column['name']]['table']);
130 return "$related::factory()"; 130 return "$related::factory()";
131 } 131 }
132 // fall through to int for lack of better option 132 // fall through to int for lack of better option
133 case 'int': 133 case 'int':
134 return "$value$nullable->randomNumber()"; 134 return "$value${nullable}->randomNumber()";
135 case 'float': 135 case 'float':
136 return "$value$nullable->randomFloat()"; 136 return "$value${nullable}->randomFloat()";
137 default: 137 default:
138 return "$value$nullable->text()"; 138 return "$value${nullable}->text()";
139 } 139 }
140 } 140 }
141 141
142 /** 142 /**
143 * Get available insertions including model relationships. 143 * Get available insertions including model relationships.