1 | <?php |
||
12 | class AdminServiceProvider extends ServiceProvider |
||
13 | { |
||
14 | protected $commands = [ |
||
15 | \Sco\Admin\Console\InstallCommand::class, |
||
16 | ]; |
||
17 | |||
18 | protected $middlewares = [ |
||
19 | 'admin.guest' => \Sco\Admin\Http\Middleware\RedirectIfAuthenticated::class, |
||
20 | 'admin.menu' => \Sco\Admin\Http\Middleware\AdminMenu::class, |
||
21 | 'admin.permissions' => \Sco\Admin\Http\Middleware\Permissions::class, |
||
22 | 'admin.phptojs' => \Sco\Admin\Http\Middleware\PHPVarToJavaScript::class, |
||
23 | 'admin.can' => \Sco\Admin\Http\Middleware\Authorize::class, |
||
24 | 'admin.role' => \Sco\Admin\Http\Middleware\EntrustRole::class, |
||
25 | ]; |
||
26 | |||
27 | public function getBasePath() |
||
31 | |||
32 | /** |
||
33 | * Bootstrap the application services. |
||
34 | * |
||
35 | * @return void |
||
36 | */ |
||
37 | public function boot() |
||
38 | { |
||
39 | // 路由文件 |
||
40 | $this->loadRoutes(); |
||
41 | |||
42 | // 后台模板目录 |
||
43 | $this->loadViewsFrom( |
||
44 | $this->getBasePath() . '/resources/views', |
||
45 | 'admin' |
||
46 | ); |
||
47 | // 后台语言包目录 |
||
48 | $this->loadTranslationsFrom( |
||
49 | $this->getBasePath() . '/resources/lang', |
||
50 | 'admin' |
||
51 | ); |
||
52 | |||
53 | if ($this->app->runningInConsole()) { |
||
54 | $this->loadMigrationsFrom($this->getBasePath() . '/database/migrations'); |
||
55 | $this->publishAdmin(); |
||
56 | } |
||
57 | |||
58 | } |
||
59 | |||
60 | protected function loadRoutes() |
||
61 | { |
||
62 | $routesFile = $this->getBasePath() . '/routes/admin.php'; |
||
63 | if (file_exists(base_path('routes/admin.php'))) { |
||
64 | $routesFile = base_path('routes/admin.php'); |
||
65 | } |
||
66 | |||
67 | $this->loadRoutesFrom($routesFile); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Register the application services. |
||
72 | * |
||
73 | * @return void |
||
74 | */ |
||
75 | public function register() |
||
76 | { |
||
77 | $this->registerMiddleware(); |
||
78 | |||
79 | $this->commands($this->commands); |
||
80 | |||
81 | $this->mergeConfigFrom( |
||
82 | $this->getBasePath() . '/config/admin.php', |
||
83 | 'admin' |
||
84 | ); |
||
85 | |||
86 | $this->registerProviders(); |
||
87 | $this->registerExceptionHandler(); |
||
88 | } |
||
89 | |||
90 | protected function registerMiddleware() |
||
91 | { |
||
92 | $router = $this->app['router']; |
||
93 | foreach ($this->middlewares as $key => $middleware) { |
||
94 | $router->aliasMiddleware($key, $middleware); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | protected function registerProviders() |
||
99 | { |
||
100 | $this->app->register(\Sco\ActionLog\LaravelServiceProvider::class); |
||
101 | $this->app->register(\Laracasts\Utilities\JavaScript\JavaScriptServiceProvider::class); |
||
102 | } |
||
103 | |||
104 | protected function registerExceptionHandler() |
||
105 | { |
||
106 | $exceptHandler = app(ExceptionHandler::class); |
||
107 | $this->app->singleton( |
||
108 | ExceptionHandler::class, |
||
109 | function () use ($exceptHandler) { |
||
110 | return new Handler($exceptHandler); |
||
111 | } |
||
112 | ); |
||
113 | } |
||
114 | |||
115 | protected function publishAdmin() |
||
123 | |||
124 | protected function publishAssets() |
||
130 | |||
131 | protected function publishConfig() |
||
137 | |||
138 | protected function publishViews() |
||
144 | |||
145 | protected function publishTranslations() |
||
151 | |||
152 | protected function publishRoutes() |
||
158 | } |
||
159 |