@@ -135,6 +135,38 @@ public static function migrate(string $fileToMigrate): bool
135135 }
136136 }
137137
138+ if ($ rememberToken !== ($ lastMigration ['remember_token ' ] ?? false )) {
139+ if ($ rememberToken && !static ::$ connection ::schema ()->hasColumn ($ tableName , 'remember_token ' )) {
140+ $ table ->rememberToken ();
141+ } else if (!$ rememberToken && static ::$ connection ::schema ()->hasColumn ($ tableName , 'remember_token ' )) {
142+ $ table ->dropRememberToken ();
143+ }
144+ }
145+
146+ if ($ softDeletes !== ($ lastMigration ['softDeletes ' ] ?? false )) {
147+ if ($ softDeletes && !static ::$ connection ::schema ()->hasColumn ($ tableName , 'deleted_at ' )) {
148+ $ table ->softDeletes ();
149+ } else if (!$ softDeletes && static ::$ connection ::schema ()->hasColumn ($ tableName , 'deleted_at ' )) {
150+ $ table ->dropSoftDeletes ();
151+ }
152+ }
153+
154+ if ($ timestamps !== ($ lastMigration ['timestamps ' ] ?? true )) {
155+ if ($ timestamps && !static ::$ connection ::schema ()->hasColumn ($ tableName , 'created_at ' )) {
156+ $ table ->timestamps ();
157+ } else if (!$ timestamps && static ::$ connection ::schema ()->hasColumn ($ tableName , 'created_at ' )) {
158+ $ table ->dropTimestamps ();
159+ }
160+ }
161+
162+ if (count ($ removedColumns ) > 0 ) {
163+ foreach ($ removedColumns as $ removedColumn ) {
164+ if (static ::$ connection ::schema ()->hasColumn ($ tableName , $ removedColumn )) {
165+ $ table ->dropColumn ($ removedColumn );
166+ }
167+ }
168+ }
169+
138170 $ newColumns = array_diff (array_keys ($ columns ), $ staticColumns );
139171
140172 if (count ($ newColumns ) > 0 ) {
@@ -245,38 +277,6 @@ public static function migrate(string $fileToMigrate): bool
245277 $ newCol ->change ();
246278 }
247279 }
248-
249- if (count ($ removedColumns ) > 0 ) {
250- foreach ($ removedColumns as $ removedColumn ) {
251- if (static ::$ connection ::schema ()->hasColumn ($ tableName , $ removedColumn )) {
252- $ table ->dropColumn ($ removedColumn );
253- }
254- }
255- }
256-
257- if ($ rememberToken !== ($ lastMigration ['remember_token ' ] ?? false )) {
258- if ($ rememberToken && !static ::$ connection ::schema ()->hasColumn ($ tableName , 'remember_token ' )) {
259- $ table ->rememberToken ();
260- } else if (!$ rememberToken && static ::$ connection ::schema ()->hasColumn ($ tableName , 'remember_token ' )) {
261- $ table ->dropRememberToken ();
262- }
263- }
264-
265- if ($ softDeletes !== ($ lastMigration ['softDeletes ' ] ?? false )) {
266- if ($ softDeletes && !static ::$ connection ::schema ()->hasColumn ($ tableName , 'deleted_at ' )) {
267- $ table ->softDeletes ();
268- } else if (!$ softDeletes && static ::$ connection ::schema ()->hasColumn ($ tableName , 'deleted_at ' )) {
269- $ table ->dropSoftDeletes ();
270- }
271- }
272-
273- if ($ timestamps !== ($ lastMigration ['timestamps ' ] ?? true )) {
274- if ($ timestamps && !static ::$ connection ::schema ()->hasColumn ($ tableName , 'created_at ' )) {
275- $ table ->timestamps ();
276- } else if (!$ timestamps && static ::$ connection ::schema ()->hasColumn ($ tableName , 'created_at ' )) {
277- $ table ->dropTimestamps ();
278- }
279- }
280280 });
281281 }
282282
0 commit comments