From 688eb40893dbd626f9a597e1b8cac3d63ffb466b Mon Sep 17 00:00:00 2001 From: Gravitano Date: Tue, 9 Jun 2015 20:36:40 +0700 Subject: [PATCH] register views, translations and config via module's service provider --- Commands/stubs/scaffold/provider.stub | 48 ++++++++++++++++++++++++++- Commands/stubs/start.stub | 4 --- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Commands/stubs/scaffold/provider.stub b/Commands/stubs/scaffold/provider.stub index 6e70e54..83f845a 100644 --- a/Commands/stubs/scaffold/provider.stub +++ b/Commands/stubs/scaffold/provider.stub @@ -11,6 +11,18 @@ class $CLASS$ extends ServiceProvider { */ protected $defer = false; + /** + * Boot the application events. + * + * @return void + */ + public function boot() + { + $this->registerConfig(); + $this->registerTranslations(); + $this->registerViews(); + } + /** * Register the service provider. * @@ -18,7 +30,7 @@ class $CLASS$ extends ServiceProvider { */ public function register() { - $this->registerConfig(); + // } /** @@ -36,6 +48,40 @@ class $CLASS$ extends ServiceProvider { ); } + /** + * Register views. + * + * @return void + */ + public function registerViews() + { + $viewPath = base_path('views/modules/$LOWER_NAME$'); + + $sourcePath = __DIR__.'/../Resources/views'; + + $this->publishes([ + $sourcePath => $viewPath + ]); + + $this->loadViewsFrom([$viewPath, $sourcePath], '$LOWER_NAME$'); + } + + /** + * Register translations. + * + * @return void + */ + public function registerTranslations() + { + $langPath = base_path('resources/lang/modules/$LOWER_NAME$'); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, '$LOWER_NAME$'); + } else { + $this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', '$LOWER_NAME$'); + } + } + /** * Get the services provided by the provider. * diff --git a/Commands/stubs/start.stub b/Commands/stubs/start.stub index 46cf725..7be329c 100644 --- a/Commands/stubs/start.stub +++ b/Commands/stubs/start.stub @@ -12,8 +12,4 @@ | */ -Lang::addNamespace('$LOWER_NAME$', __DIR__.'/Resources/lang'); - -View::addNamespace('$LOWER_NAME$', __DIR__.'/Resources/views'); - require __DIR__ . '/Http/routes.php';