2
2
3
3
namespace ProtoneMedia \LaravelVerifyNewEmail ;
4
4
5
+ use Illuminate \Filesystem \Filesystem ;
6
+ use Illuminate \Support \Collection ;
5
7
use Illuminate \Support \ServiceProvider as BaseServiceProvider ;
6
8
7
9
class ServiceProvider extends BaseServiceProvider
8
10
{
9
11
/**
10
12
* Bootstrap the application services.
11
13
*/
12
- public function boot ()
14
+ public function boot (Filesystem $ filesystem )
13
15
{
14
16
$ this ->loadViewsFrom (__DIR__ . '/../resources/views ' , 'verify-new-email ' );
15
- $ this ->loadMigrationsFrom (__DIR__ . '/../database/migrations ' );
16
-
17
- if (!class_exists ('CreatePendingUserEmailsTable ' )) {
18
- $ this ->publishes ([
19
- __DIR__ . '/../database/migrations/create_pending_user_emails_table.php.stub ' => database_path ('migrations/ ' . date ('Y_m_d_His ' , time ()) . '_create_pending_user_emails_table.php ' ),
20
- ], 'migrations ' );
21
- }
22
17
23
18
if (!config ('verify-new-email.route ' )) {
24
19
$ this ->loadRoutesFrom (__DIR__ . '/routes.php ' );
25
20
}
26
21
27
22
if ($ this ->app ->runningInConsole ()) {
23
+ $ this ->publishes ([
24
+ __DIR__ . '/../database/migrations/create_pending_user_emails_table.php.stub ' => $ this ->getMigrationFileName ($ filesystem ),
25
+ ], 'migrations ' );
26
+
28
27
$ this ->publishes ([
29
28
__DIR__ . '/../config/config.php ' => config_path ('verify-new-email.php ' ),
30
29
], 'config ' );
@@ -37,12 +36,29 @@ public function boot()
37
36
}
38
37
}
39
38
39
+ /**
40
+ * Returns existing migration file if found, else uses the current timestamp.
41
+ *
42
+ * @param Filesystem $filesystem
43
+ * @return string
44
+ */
45
+ protected function getMigrationFileName (Filesystem $ filesystem ): string
46
+ {
47
+ $ timestamp = date ('Y_m_d_His ' );
48
+
49
+ return Collection::make ($ this ->app ->databasePath ('migrations ' ) . DIRECTORY_SEPARATOR )
50
+ ->flatMap (function ($ path ) use ($ filesystem ) {
51
+ return $ filesystem ->glob ("{$ path }*_create_pending_user_emails_table.php " );
52
+ })
53
+ ->push ($ this ->app ->databasePath ("migrations/ {$ timestamp }_create_pending_user_emails_table.php " ))
54
+ ->first ();
55
+ }
56
+
40
57
/**
41
58
* Register the application services.
42
59
*/
43
60
public function register ()
44
61
{
45
- // Automatically apply the package configuration
46
62
$ this ->mergeConfigFrom (__DIR__ . '/../config/config.php ' , 'verify-new-email ' );
47
63
}
48
64
}
0 commit comments