diff --git a/src/Base/BaseServiceProvider.php b/src/Base/BaseServiceProvider.php new file mode 100644 index 0000000..de9bce6 --- /dev/null +++ b/src/Base/BaseServiceProvider.php @@ -0,0 +1,76 @@ +packagePath("config/{$this->name}.php"); + $this->mergeConfigFrom($file, "laravolt.{$this->name}"); + $this->publishes([$file => config_path("laravolt/{$this->name}.php")], 'config'); + + $this->config = collect(config("laravolt.{$this->name}")); + } + + public function boot() + { + $this->bootRoutes() + ->bootMigrations() + ->bootViews(); + } + + protected function bootRoutes() + { + if (Arr::get($this->config, 'route.enabled')) { + $router = $this->app['router']; + require $this->packagePath('routes/web.php'); + } + + return $this; + } + + protected function bootViews() + { + $viewFolder = $this->packagePath('resources/views'); + $this->loadViewsFrom($viewFolder, $this->name); + $this->publishes( + [$viewFolder => base_path("resources/views/vendor/{$this->name}}")], + 'views' + ); + + return $this; + } + + protected function bootMigrations() + { + $databaseFolder = $this->packagePath('database/migrations'); + if ($this->app->runningInConsole()) { + $this->loadMigrationsFrom($databaseFolder); + } + $this->publishes([ + $databaseFolder => database_path('migrations'), + ], 'migrations'); + + return $this; + } + + protected function packagePath($path) + { + $rc = new \ReflectionClass(get_class($this)); + $dir = dirname($rc->getFileName()); + + return sprintf('%s/../%s', $dir, $path); + } +}