From 9ebae895a16e5fdccdc7f7a71154470871a279af Mon Sep 17 00:00:00 2001 From: Victor Kislichenko Date: Thu, 2 Dec 2021 19:03:04 +0200 Subject: [PATCH 1/2] config option: Manual migrations --- README.md | 2 +- config/laravel-database-emails.php | 13 ++++++++ src/LaravelDatabaseEmailsServiceProvider.php | 33 ++++++++++++++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9c49847..058a2e3 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ composer require stackkit/laravel-database-emails Publish the configuration files. ```bash -php artisan vendor:publish --provider=Stackkit\\LaravelDatabaseEmails\\LaravelDatabaseEmailsServiceProvider +php artisan vendor:publish --tag=laravel-database-emails-config ``` Create the database table required for this package. diff --git a/config/laravel-database-emails.php b/config/laravel-database-emails.php index ef9c2f4..8a7b553 100644 --- a/config/laravel-database-emails.php +++ b/config/laravel-database-emails.php @@ -71,4 +71,17 @@ */ 'immediately' => env('LARAVEL_DATABASE_EMAILS_SEND_IMMEDIATELY', false), + + /* + |-------------------------------------------------------------------------- + | Manual migrations + |-------------------------------------------------------------------------- + | + | This option allows you to use: + | `php artisan vendor:publish --tag=laravel-database-emails-migrations` to push migrations + | to your app's folder so you're free to modify before migrating. + | + */ + + 'manual_migrations' => (bool) env('LARAVEL_DATABASE_EMAILS_MANUAL_MIGRATIONS', false), ]; diff --git a/src/LaravelDatabaseEmailsServiceProvider.php b/src/LaravelDatabaseEmailsServiceProvider.php index 2e0d1d9..846fe9f 100644 --- a/src/LaravelDatabaseEmailsServiceProvider.php +++ b/src/LaravelDatabaseEmailsServiceProvider.php @@ -12,16 +12,43 @@ class LaravelDatabaseEmailsServiceProvider extends ServiceProvider * @return void */ public function boot() + { + $this->bootConfig(); + $this->bootDatabase(); + } + + /** + * Boot the config for the package. + * + * @return void + */ + private function bootConfig(): void { $baseDir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; $configDir = $baseDir . 'config' . DIRECTORY_SEPARATOR; - $migrationsDir = $baseDir . 'database' . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR; $this->publishes([ $configDir . 'laravel-database-emails.php' => config_path('laravel-database-emails.php'), - ]); + ], 'laravel-database-emails-config'); + } + + /** + * Boot the database for the package. + * + * @return void + */ + private function bootDatabase(): void + { + $baseDir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; + $migrationsDir = $baseDir . 'database' . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR; - $this->loadMigrationsFrom([$migrationsDir]); + if ($this->app['config']->get('laravel-database-emails.manual_migrations')) { + $this->publishes([ + $migrationsDir => "{$this->app->databasePath()}/migrations", + ], 'laravel-database-emails-migrations'); + } else { + $this->loadMigrationsFrom([$migrationsDir]); + } } /** From b7aba53aabfa57e4dcf685c9fef786d0325a1d33 Mon Sep 17 00:00:00 2001 From: Victor Kislichenko Date: Thu, 2 Dec 2021 22:17:17 +0200 Subject: [PATCH 2/2] Email::compose(): replaced `self` with `static` to fix cases when we are working with extended model --- src/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Email.php b/src/Email.php index f4a30bf..2052440 100644 --- a/src/Email.php +++ b/src/Email.php @@ -52,7 +52,7 @@ class Email extends Model */ public static function compose() { - return new EmailComposer(new self); + return new EmailComposer(new static); } /**