File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ class DummyModelClass extends Model
13
13
14
14
protected $ guarded = [];
15
15
16
+ public $ migration_sequence = 1 ;
17
+
16
18
public function migration (Blueprint $ table )
17
19
{
18
20
$ table ->id ();
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ class DummyModelClass extends Authenticatable
18
18
protected $ hashes = ['password ' ];
19
19
protected $ hidden = ['password ' , 'remember_token ' ];
20
20
protected $ casts = ['email_verified_at ' => 'datetime ' ];
21
+ public $ migration_sequence = 0 ;
21
22
22
23
public function migration (Blueprint $ table )
23
24
{
Original file line number Diff line number Diff line change @@ -64,6 +64,27 @@ private function runAutomaticMigrations()
64
64
$ this ->migrate ($ model );
65
65
}
66
66
}
67
+
68
+ $ models_to_migrate = collect ([]);
69
+
70
+ foreach ((new Finder )->in ($ path ) as $ model ) {
71
+ $ model = $ namespace . str_replace (
72
+ ['/ ' , '.php ' ],
73
+ ['\\' , '' ],
74
+ Str::after ($ model ->getRealPath (), realpath (app_path ()) . DIRECTORY_SEPARATOR )
75
+ );
76
+
77
+ if (method_exists ($ model , 'migration ' )) {
78
+ $ model_object = app ($ model );
79
+ $ models_to_migrate [] = ['sequence ' => $ model_object ->migration_sequence ?? 1 , 'model ' => $ model ];
80
+ }
81
+ }
82
+
83
+ $ sorted_models_to_migrate = $ models_to_migrate ->sortBy ('sequence ' );
84
+
85
+ foreach ($ sorted_models_to_migrate as $ model ) {
86
+ $ this ->migrate ($ model ['model ' ]);
87
+ }
67
88
}
68
89
69
90
private function migrate ($ class )
You can’t perform that action at this time.
0 commit comments