@@ -18,19 +18,17 @@ class MigrationGenerator implements Generator
18
18
];
19
19
20
20
const UNSIGNABLE_TYPES = [
21
- 'bigInteger ' ,
22
- 'decimal ' ,
23
- 'integer ' ,
24
- 'mediumInteger ' ,
25
- 'smallInteger ' ,
26
- 'tinyInteger ' ,
21
+ 'bigInteger ' ,
22
+ 'decimal ' ,
23
+ 'integer ' ,
24
+ 'mediumInteger ' ,
25
+ 'smallInteger ' ,
26
+ 'tinyInteger ' ,
27
27
];
28
28
29
29
/** @var \Illuminate\Contracts\Filesystem\Filesystem */
30
30
private $ files ;
31
31
32
- private $ pivotTables = [];
33
-
34
32
public function __construct ($ files )
35
33
{
36
34
$ this ->files = $ files ;
@@ -39,6 +37,7 @@ public function __construct($files)
39
37
public function output (array $ tree ): array
40
38
{
41
39
$ output = [];
40
+ $ created_pivot_tables = [];
42
41
43
42
$ stub = $ this ->files ->stub ('migration.stub ' );
44
43
@@ -51,24 +50,18 @@ public function output(array $tree): array
51
50
52
51
$ output ['created ' ][] = $ path ;
53
52
54
- if (!empty ($ modelPivots = $ model ->pivotTables ())) {
55
- foreach ($ modelPivots as $ pivotSegments ) {
53
+ if (!empty ($ model ->pivotTables ())) {
54
+ foreach ($ model -> pivotTables () as $ pivotSegments ) {
56
55
$ pivotTable = $ this ->getPivotTableName ($ pivotSegments );
57
- if (!isset ($ this ->pivotTables [$ pivotTable ])) {
58
- $ this ->pivotTables [$ pivotTable ] = [
59
- 'tableName ' => $ pivotTable ,
60
- 'segments ' => $ pivotSegments
61
- ];
56
+ if (isset ($ created_pivot_tables [$ pivotTable ])) {
57
+ continue ;
62
58
}
63
- }
64
- }
65
- }
66
59
67
- if (! empty ( $ this ->pivotTables )) {
68
- foreach ( $ this ->pivotTables as $ pivotTable ) {
69
- $ path = $ this -> getPivotTablePath ( $ pivotTable [ ' tableName ' ], $ sequential_timestamp -> addSecond ()) ;
70
- $ this -> files -> put ( $ path , $ this -> populatePivotStub ( $ stub , $ pivotTable [ ' segments ' ])) ;
71
- $ output [ ' created ' ][] = $ path ;
60
+ $ path = $ this ->getPivotTablePath ( $ pivotTable , $ sequential_timestamp );
61
+ $ this -> files -> put ( $ path , $ this ->populatePivotStub ( $ stub , $ pivotSegments ));
62
+ $ created_pivot_tables [] = $ pivotTable ;
63
+ $ output [ ' created ' ][] = $ path ;
64
+ }
72
65
}
73
66
}
74
67
0 commit comments