@@ -74,15 +74,35 @@ protected function buildDefinition(Model $model)
74
74
$ definition .= self ::INDENT . "' {$ column ->name ()}' => " ;
75
75
$ definition .= sprintf ("factory(%s::class) " , '\\' . $ model ->fullyQualifiedNamespace () . '\\' . $ class );
76
76
$ definition .= ', ' . PHP_EOL ;
77
- } else {
77
+ } else if (in_array ($ column ->dataType (), ['enum ' , 'set ' ]) and !empty ($ column ->attributes ())){
78
+ $ definition .= self ::INDENT . "' {$ column ->name ()}' => " ;
79
+ $ faker = $ this ->fakerData ($ column ->name ()) ?? $ this ->fakerDataType ($ column ->dataType ());
80
+ $ definition .= '$faker-> ' . $ faker ;
81
+ $ definition .= ', ' . PHP_EOL ;
82
+ $ definition = str_replace (
83
+ "/** {$ column ->dataType ()}_attributes **/ " ,
84
+ json_encode ($ column ->attributes ()),
85
+ $ definition
86
+ );
87
+ } else if (in_array ($ column ->dataType (), ['decimal ' , 'float ' ])) {
78
88
$ definition .= self ::INDENT . "' {$ column ->name ()}' => " ;
79
89
$ faker = $ this ->fakerData ($ column ->name ()) ?? $ this ->fakerDataType ($ column ->dataType ());
80
90
$ definition .= '$faker-> ' . $ faker ;
81
91
$ definition .= ', ' . PHP_EOL ;
82
92
83
- if (in_array ($ column ->dataType (), ['enum ' , 'set ' ]) and !empty ($ column ->attributes ())) {
84
- $ definition = str_replace ("/** {$ column ->dataType ()}_attributes **/ " , json_encode ($ column ->attributes ()), $ definition );
85
- }
93
+ $ precision = min ([65 , intval ($ column ->attributes ()[0 ] ?? 10 )]);
94
+ $ scale = min ([30 , max ([0 , intval ($ column ->attributes ()[1 ] ?? 0 )])]);
95
+
96
+ $ definition = str_replace (
97
+ "/** {$ column ->dataType ()}_attributes **/ " ,
98
+ implode (', ' , [$ precision , 0 , (intval (str_repeat (9 , $ precision )) / pow (10 , $ scale ))]),
99
+ $ definition
100
+ );
101
+ } else {
102
+ $ definition .= self ::INDENT . "' {$ column ->name ()}' => " ;
103
+ $ faker = $ this ->fakerData ($ column ->name ()) ?? $ this ->fakerDataType ($ column ->dataType ());
104
+ $ definition .= '$faker-> ' . $ faker ;
105
+ $ definition .= ', ' . PHP_EOL ;
86
106
}
87
107
}
88
108
@@ -145,8 +165,8 @@ protected function fakerDataType(string $type)
145
165
'integer ' => 'randomNumber() ' ,
146
166
'bigint ' => 'randomNumber() ' ,
147
167
'smallint ' => 'randomNumber() ' ,
148
- 'decimal ' => 'randomFloat() ' ,
149
- 'float ' => 'randomFloat() ' ,
168
+ 'decimal ' => 'randomFloat(/** decimal_attributes **/ ) ' ,
169
+ 'float ' => 'randomFloat(/** float_attributes **/ ) ' ,
150
170
'longtext ' => 'text ' ,
151
171
'boolean ' => 'boolean ' ,
152
172
'set ' => 'randomElement(/** set_attributes **/) ' ,
0 commit comments