1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\Base; |
4
|
|
|
|
5
|
|
|
use Illuminate\Routing\Router; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use Route; |
8
|
|
|
|
9
|
|
|
class BaseServiceProvider extends ServiceProvider |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Indicates if loading of the provider is deferred. |
13
|
|
|
* |
14
|
|
|
* @var bool |
15
|
|
|
*/ |
16
|
|
|
protected $defer = false; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Perform post-registration booting of services. |
20
|
|
|
* |
21
|
|
|
* @return void |
22
|
|
|
*/ |
23
|
|
|
public function boot(\Illuminate\Routing\Router $router) |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
// LOAD THE VIEWS |
26
|
|
|
// - first the published views (in case they have any changes) |
27
|
|
|
$this->loadViewsFrom(resource_path('views/vendor/backpack/base'), 'backpack'); |
28
|
|
|
// - then the stock views that come with the package, in case a published view might be missing |
29
|
|
|
$this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'backpack'); |
30
|
|
|
|
31
|
|
|
$this->loadTranslationsFrom(realpath(__DIR__.'/resources/lang'), 'backpack'); |
32
|
|
|
|
33
|
|
|
// use the vendor configuration file as fallback |
34
|
|
|
$this->mergeConfigFrom( |
35
|
|
|
__DIR__.'/config/backpack/base.php', 'backpack.base' |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
$this->registerAdminMiddleware($this->app->router); |
|
|
|
|
39
|
|
|
$this->setupRoutes($this->app->router); |
|
|
|
|
40
|
|
|
$this->publishFiles(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Define the routes for the application. |
45
|
|
|
* |
46
|
|
|
* @param \Illuminate\Routing\Router $router |
47
|
|
|
* |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
public function setupRoutes(Router $router) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
Route::group( |
53
|
|
|
[ |
54
|
|
|
'namespace' => 'Backpack\Base\app\Http\Controllers', |
55
|
|
|
'middleware' => 'web', |
56
|
|
|
'prefix' => config('backpack.base.route_prefix'), |
57
|
|
|
], |
58
|
|
|
function () { |
59
|
|
|
// if not otherwise configured, setup the auth routes |
60
|
|
|
if (config('backpack.base.setup_auth_routes')) { |
61
|
|
|
Route::auth(); |
62
|
|
|
Route::get('logout', 'Auth\LoginController@logout'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
// if not otherwise configured, setup the dashboard routes |
66
|
|
|
if (config('backpack.base.setup_dashboard_routes')) { |
67
|
|
|
Route::get('dashboard', 'AdminController@dashboard'); |
68
|
|
|
Route::get('/', 'AdminController@redirect'); |
69
|
|
|
} |
70
|
|
|
}); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Register any package services. |
75
|
|
|
* |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
public function register() |
79
|
|
|
{ |
80
|
|
|
// register the current package |
81
|
|
|
$this->app->bind('base', function ($app) { |
82
|
|
|
return new Base($app); |
83
|
|
|
}); |
84
|
|
|
|
85
|
|
|
// register its dependencies |
86
|
|
|
$this->app->register(\Jenssegers\Date\DateServiceProvider::class); |
87
|
|
|
$this->app->register(\Prologue\Alerts\AlertsServiceProvider::class); |
88
|
|
|
|
89
|
|
|
// register their aliases |
90
|
|
|
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
91
|
|
|
$loader->alias('Alert', \Prologue\Alerts\Facades\Alert::class); |
92
|
|
|
$loader->alias('Date', \Jenssegers\Date\Date::class); |
93
|
|
|
|
94
|
|
|
// register the services that are only used for development |
95
|
|
|
if ($this->app->environment() == 'local') { |
96
|
|
|
if (class_exists('Laracasts\Generators\GeneratorsServiceProvider')) { |
97
|
|
|
$this->app->register('Laracasts\Generators\GeneratorsServiceProvider'); |
98
|
|
|
} |
99
|
|
|
if (class_exists('Backpack\Generators\GeneratorsServiceProvider')) { |
100
|
|
|
$this->app->register('Backpack\Generators\GeneratorsServiceProvider'); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function registerAdminMiddleware(Router $router) |
106
|
|
|
{ |
107
|
|
|
// in Laravel 5.4 |
108
|
|
|
if (method_exists($router, 'aliasMiddleware')) |
109
|
|
|
{ |
110
|
|
|
Route::aliasMiddleware('admin', \Backpack\Base\app\Http\Middleware\Admin::class); |
111
|
|
|
} |
112
|
|
|
// in Laravel 5.3 and below |
113
|
|
|
else |
114
|
|
|
{ |
115
|
|
|
Route::middleware('admin', \Backpack\Base\app\Http\Middleware\Admin::class); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function publishFiles() |
120
|
|
|
{ |
121
|
|
|
// publish config file |
122
|
|
|
$this->publishes([__DIR__.'/config' => config_path()], 'config'); |
123
|
|
|
|
124
|
|
|
// publish lang files |
125
|
|
|
$this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack')], 'lang'); |
126
|
|
|
|
127
|
|
|
// publish views |
128
|
|
|
$this->publishes([__DIR__.'/resources/views' => resource_path('views/vendor/backpack/base')], 'views'); |
129
|
|
|
|
130
|
|
|
// publish error views |
131
|
|
|
$this->publishes([__DIR__.'/resources/error_views' => resource_path('views/errors')], 'errors'); |
132
|
|
|
|
133
|
|
|
// publish public Backpack assets |
134
|
|
|
$this->publishes([__DIR__.'/public' => public_path('vendor/backpack')], 'public'); |
135
|
|
|
|
136
|
|
|
// publish public AdminLTE assets |
137
|
|
|
$this->publishes([base_path('vendor/almasaeed2010/adminlte') => public_path('vendor/adminlte')], 'adminlte'); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.