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/Email.php b/src/Email.php index 8dbcd0d..efb3952 100644 --- a/src/Email.php +++ b/src/Email.php @@ -53,7 +53,7 @@ class Email extends Model */ public static function compose() { - return new EmailComposer(new self); + return new EmailComposer(new static); } /** 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]); + } } /**