AdminServiceProvider.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Modules\Admin\Providers;
  3. use Illuminate\Support\ServiceProvider;
  4. use Illuminate\Database\Eloquent\Factory;
  5. class AdminServiceProvider extends ServiceProvider
  6. {
  7. /**
  8. * Indicates if loading of the provider is deferred.
  9. *
  10. * @var bool
  11. */
  12. protected $defer = false;
  13. /**
  14. * Boot the application events.
  15. *
  16. * @return void
  17. */
  18. public function boot()
  19. {
  20. $this->registerTranslations();
  21. $this->registerConfig();
  22. $this->registerViews();
  23. $this->registerFactories();
  24. $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
  25. }
  26. /**
  27. * Register the service provider.
  28. *
  29. * @return void
  30. */
  31. public function register()
  32. {
  33. //
  34. }
  35. /**
  36. * Register config.
  37. *
  38. * @return void
  39. */
  40. protected function registerConfig()
  41. {
  42. $this->publishes([
  43. __DIR__.'/../Config/config.php' => config_path('admin.php'),
  44. ], 'config');
  45. $this->mergeConfigFrom(
  46. __DIR__.'/../Config/config.php', 'admin'
  47. );
  48. }
  49. /**
  50. * Register views.
  51. *
  52. * @return void
  53. */
  54. public function registerViews()
  55. {
  56. $viewPath = resource_path('views/modules/admin');
  57. $sourcePath = __DIR__.'/../Resources/views';
  58. $this->publishes([
  59. $sourcePath => $viewPath
  60. ],'views');
  61. $this->loadViewsFrom(array_merge(array_map(function ($path) {
  62. return $path . '/modules/admin';
  63. }, \Config::get('view.paths')), [$sourcePath]), 'admin');
  64. }
  65. /**
  66. * Register translations.
  67. *
  68. * @return void
  69. */
  70. public function registerTranslations()
  71. {
  72. $langPath = resource_path('lang/modules/admin');
  73. if (is_dir($langPath)) {
  74. $this->loadTranslationsFrom($langPath, 'admin');
  75. } else {
  76. $this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'admin');
  77. }
  78. }
  79. /**
  80. * Register an additional directory of factories.
  81. *
  82. * @return void
  83. */
  84. public function registerFactories()
  85. {
  86. if (! app()->environment('production')) {
  87. app(Factory::class)->load(__DIR__ . '/../Database/factories');
  88. }
  89. }
  90. /**
  91. * Get the services provided by the provider.
  92. *
  93. * @return array
  94. */
  95. public function provides()
  96. {
  97. return [];
  98. }
  99. }