File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use Blueprint \Contracts \Generator ;
6
6
use Blueprint \Models \Model ;
7
+ use Illuminate \Support \Str ;
7
8
8
9
class FactoryGenerator implements Generator
9
10
{
@@ -61,10 +62,19 @@ protected function buildDefinition(Model $model)
61
62
continue ;
62
63
}
63
64
64
- $ definition .= self ::INDENT . "' {$ column ->name ()}' => " ;
65
- $ faker = $ this ->fakerData ($ column ->name ()) ?? $ this ->fakerDataType ($ column ->dataType ());
66
- $ definition .= '$faker-> ' . $ faker ;
67
- $ definition .= ', ' . PHP_EOL ;
65
+ if ($ column ->dataType () === 'id ' ) {
66
+ $ name = Str::substr ($ column ->name (), 0 , -3 );
67
+ $ class = Str::studly ($ column ->attributes ()[0 ] ?? $ name );
68
+
69
+ $ definition .= self ::INDENT . "' {$ column ->name ()}' => " ;
70
+ $ definition .= sprintf ("factory(\App\%s::class) " , $ class );
71
+ $ definition .= ', ' . PHP_EOL ;
72
+ } else {
73
+ $ definition .= self ::INDENT . "' {$ column ->name ()}' => " ;
74
+ $ faker = $ this ->fakerData ($ column ->name ()) ?? $ this ->fakerDataType ($ column ->dataType ());
75
+ $ definition .= '$faker-> ' . $ faker ;
76
+ $ definition .= ', ' . PHP_EOL ;
77
+ }
68
78
}
69
79
70
80
return trim ($ definition );
You can’t perform that action at this time.
0 commit comments