22
33namespace Rayiumir \Vordia \ServiceProvider ;
44
5+ use Illuminate \Support \Facades \File ;
6+ use Illuminate \Support \Facades \Log ;
57use Illuminate \Support \ServiceProvider ;
68
79class VordiaServiceProvider extends ServiceProvider
@@ -14,6 +16,12 @@ class VordiaServiceProvider extends ServiceProvider
1416 public function register (): void
1517 {
1618 $ this ->mergeConfigFrom (__DIR__ . '/../../config/vordia.php ' , 'vordia ' );
19+
20+ if ($ this ->app ->runningInConsole ()) {
21+
22+ $ this ->replaceUsersMigration ();
23+
24+ }
1725 }
1826
1927 /**
@@ -25,7 +33,6 @@ public function boot(): void
2533 {
2634 $ this ->_loadRoutes ();
2735 $ this ->_loadViews ();
28- $ this ->_loadMigrations ();
2936 $ this ->_loadScripts ();
3037 $ this ->_loadController ();
3138 $ this ->_loadConfig ();
@@ -49,16 +56,6 @@ private function _loadRoutes(): void
4956 private function _loadViews (): void
5057 {
5158 $ this ->loadViewsFrom (__DIR__ . '/../Resources/views ' , 'Vordia ' );
52-
53- $ this ->publishes ([__DIR__ . '/../Resources/views ' => resource_path ('views/ ' )], 'vordia-views ' );
54-
55- }
56-
57- private function _loadMigrations (): void
58- {
59- $ this ->loadMigrationsFrom (__DIR__ . '/../Database/migrations ' );
60-
61- $ this ->publishes ([__DIR__ . '/../Database/migrations ' => database_path ('migrations ' )], 'vordia-migrations ' );
6259 }
6360
6461 private function _loadScripts (): void
@@ -83,8 +80,32 @@ private function _loadController(): void
8380
8481 private function _loadConfig (): void
8582 {
86- $ this ->publishes ([__DIR__ . '/../../config ' => config_path ('/config ' ),], 'vordia-config ' );
83+ $ this ->publishes ([__DIR__ . '/../../config ' => config_path ('/ ' ),], 'vordia-config ' );
8784 }
8885
86+ protected function replaceUsersMigration (): void
87+ {
88+ $ migrationsPath = database_path ('migrations ' );
89+ $ files = File::glob ($ migrationsPath . '/*_users_table.php ' );
90+
91+ if (!empty ($ files )) {
92+ File::put ($ files [0 ], File::get (__DIR__ .'/../Stubs/create_users_table.php.stub ' ));
93+ $ this ->info ('Default users migration has been replaced with nullable version. ' );
94+ } else {
95+ $ this ->publishes ([
96+ __DIR__ .'/../Stubs/create_users_table.php.stub ' => $ this ->getMigrationFilename ('create_users_table.php ' ),
97+ ], 'migrations ' );
98+ }
99+ }
100+
101+ protected function getMigrationFilename ($ migrationName ): string
102+ {
103+ return database_path ('migrations ' ) . '/ ' . date ('Y_m_d_His ' ) . '_ ' . $ migrationName ;
104+ }
105+
106+ protected function info ($ message ): void
107+ {
108+ Log::info ($ message );
109+ }
89110}
90111
0 commit comments