From 4fdcd22ab13f009e7949bbb5996b26965f5367ec Mon Sep 17 00:00:00 2001 From: Mark Sitko Date: Thu, 19 Nov 2020 21:44:58 +0100 Subject: [PATCH] Fix and improve service provider --- src/LaravelCustomFieldsServiceProvider.php | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/LaravelCustomFieldsServiceProvider.php b/src/LaravelCustomFieldsServiceProvider.php index a6a5ddd..feba44f 100644 --- a/src/LaravelCustomFieldsServiceProvider.php +++ b/src/LaravelCustomFieldsServiceProvider.php @@ -8,14 +8,28 @@ class LaravelCustomFieldsServiceProvider extends ServiceProvider { public function boot() { - $this->publishes([ - __DIR__ . '/../config/custom-fields.php' => config_path('custom-fields.php'), - ]); - - if (!class_exists('CreateCustomFieldsTables')) { + /* + * Optional methods to load your package assets + */ + if ($this->app->runningInConsole()) { $this->publishes([ - __DIR__ . '/../database/migrations/create_custom_fields_tables.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_custom_fields_tables.php'), - ], 'migrations'); + __DIR__.'/../config/custom-fields.php' => config_path('custom-fields.php'), + ], 'config'); + + if (! class_exists('CreateCustomFieldsTables')) { + $this->publishes([ + __DIR__.'/../database/migrations/create_custom_fields_tables.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_custom_fields_tables.php'), + ], 'migrations'); + } } } + + /** + * Register the application services. + */ + public function register() + { + // Automatically apply the package configuration + $this->mergeConfigFrom(__DIR__.'/../config/custom-fields.php', 'custom-fields'); + } }