1 | <?php |
||||
2 | |||||
3 | namespace Enomotodev\LaractiveAdmin; |
||||
4 | |||||
5 | use Collective\Html\FormFacade; |
||||
6 | use Collective\Html\HtmlFacade; |
||||
7 | use Intervention\Httpauth\Httpauth; |
||||
8 | use Collective\Html\HtmlServiceProvider; |
||||
9 | use Enomotodev\LaractiveAdmin\Console\SeedCommand; |
||||
10 | use Intervention\Httpauth\HttpauthServiceProvider; |
||||
11 | use Enomotodev\LaractiveAdmin\Console\InstallCommand; |
||||
12 | use Enomotodev\LaractiveAdmin\Console\UninstallCommand; |
||||
13 | use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
||||
14 | use Enomotodev\LaractiveAdmin\Http\Middleware\HttpauthAuthenticate; |
||||
15 | use Enomotodev\LaractiveAdmin\Http\Middleware\SharingDataWithAllViews; |
||||
16 | use Enomotodev\LaractiveAdmin\Http\Middleware\LaractiveAdminAuthenticate; |
||||
17 | |||||
18 | class ServiceProvider extends BaseServiceProvider |
||||
19 | { |
||||
20 | /** |
||||
21 | * Bootstrap the application events. |
||||
22 | * |
||||
23 | * @return void |
||||
24 | */ |
||||
25 | 11 | public function boot() |
|||
26 | { |
||||
27 | 11 | $this->publishes([$this->configPath() => config_path('laractive-admin.php')], 'config'); |
|||
28 | |||||
29 | 11 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'laractive-admin'); |
|||
30 | |||||
31 | $routeConfig = [ |
||||
32 | 11 | 'middleware' => ['web', 'laractive-admin', 'httpauth', 'sharing-data'], |
|||
33 | 11 | 'namespace' => 'App\Admin', |
|||
34 | 11 | 'prefix' => $this->app['config']->get('laractive-admin.route_prefix'), |
|||
35 | 11 | 'as' => 'admin.', |
|||
36 | 'where' => [ |
||||
37 | 'id' => '[0-9]+', |
||||
38 | ], |
||||
39 | ]; |
||||
40 | |||||
41 | 11 | if (is_dir($directory = app_path('Admin'))) { |
|||
42 | 11 | $this->getRouter()->group($routeConfig, function ($router) { |
|||
43 | /** @var $router \Illuminate\Routing\Router */ |
||||
44 | 11 | $files = $this->getFilesystem()->allFiles(app_path('Admin')); |
|||
45 | |||||
46 | 11 | foreach ($files as $file) { |
|||
47 | 11 | $filename = $file->getFilename(); |
|||
48 | 11 | $className = substr($filename, 0, -4); |
|||
49 | /** @var \Enomotodev\LaractiveAdmin\Http\Controllers\Controller $adminClassName */ |
||||
50 | 11 | $adminClassName = "\App\Admin\\{$className}"; |
|||
51 | 11 | $adminClass = new $adminClassName; |
|||
52 | 11 | $routePrefix = $adminClass->model ? (new $adminClass->model)->getTable() : strtolower($className); |
|||
53 | 11 | if ($adminClass->model) { |
|||
54 | 11 | $router->get("{$routePrefix}", [ |
|||
55 | 11 | 'uses' => "\App\Admin\\{$className}@index", |
|||
56 | 11 | 'as' => "{$routePrefix}.index", |
|||
57 | ]); |
||||
58 | 11 | $router->get("{$routePrefix}/{id}", [ |
|||
59 | 11 | 'uses' => "\App\Admin\\{$className}@show", |
|||
60 | 11 | 'as' => "{$routePrefix}.show", |
|||
61 | ]); |
||||
62 | 11 | $router->get("{$routePrefix}/new", [ |
|||
63 | 11 | 'uses' => "\App\Admin\\{$className}@new", |
|||
64 | 11 | 'as' => "{$routePrefix}.new", |
|||
65 | ]); |
||||
66 | 11 | $router->post("{$routePrefix}", [ |
|||
67 | 11 | 'uses' => "\App\Admin\\{$className}@create", |
|||
68 | 11 | 'as' => "{$routePrefix}.create", |
|||
69 | ]); |
||||
70 | 11 | $router->get("{$routePrefix}/{id}/edit", [ |
|||
71 | 11 | 'uses' => "\App\Admin\\{$className}@edit", |
|||
72 | 11 | 'as' => "{$routePrefix}.edit", |
|||
73 | ]); |
||||
74 | 11 | $router->put("{$routePrefix}/{id}", [ |
|||
75 | 11 | 'uses' => "\App\Admin\\{$className}@update", |
|||
76 | 11 | 'as' => "{$routePrefix}.update", |
|||
77 | ]); |
||||
78 | 11 | $router->delete("{$routePrefix}/{id}", [ |
|||
79 | 11 | 'uses' => "\App\Admin\\{$className}@destroy", |
|||
80 | 11 | 'as' => "{$routePrefix}.destroy", |
|||
81 | ]); |
||||
82 | 11 | $router->post("{$routePrefix}/{id}/comments", [ |
|||
83 | 11 | 'uses' => "\App\Admin\\{$className}@comments", |
|||
84 | 11 | 'as' => "{$routePrefix}.comments", |
|||
85 | ]); |
||||
86 | } |
||||
87 | |||||
88 | 11 | foreach ($adminClassName::$actions as $route) { |
|||
89 | 11 | $router->{$route['method']}($route['uri'], [ |
|||
90 | 11 | 'uses' => "\App\Admin\\{$className}@{$route['action']}", |
|||
91 | 11 | 'as' => "{$routePrefix}.{$route['action']}", |
|||
92 | ]); |
||||
93 | } |
||||
94 | |||||
95 | 11 | if ($className !== 'Dashboard') { |
|||
96 | 11 | app(Menu::class)->setPage([ |
|||
97 | 11 | 'name' => $className, |
|||
98 | 11 | 'url' => route("admin.{$routePrefix}.index"), |
|||
99 | ]); |
||||
100 | } |
||||
101 | } |
||||
102 | 11 | }); |
|||
103 | } |
||||
104 | |||||
105 | // Authentication |
||||
106 | 11 | $this->getRouter()->group([ |
|||
107 | 11 | 'middleware' => ['web', 'httpauth'], |
|||
108 | 11 | 'prefix' => $this->app['config']->get('laractive-admin.route_prefix'), |
|||
109 | 11 | ], function ($router) { |
|||
110 | /* @var $router \Illuminate\Routing\Router */ |
||||
111 | 11 | $router->get('login', [ |
|||
112 | 11 | 'uses' => '\Enomotodev\LaractiveAdmin\Http\Controllers\Auth\LoginController@showLoginForm', |
|||
0 ignored issues
–
show
|
|||||
113 | 'as' => 'admin.login', |
||||
114 | ]); |
||||
115 | 11 | $router->post('login', [ |
|||
116 | 11 | 'uses' => '\Enomotodev\LaractiveAdmin\Http\Controllers\Auth\LoginController@login', |
|||
0 ignored issues
–
show
The controller
App\Http\Controllers\\En...rs\Auth\LoginController does not seem to exist.
If there is a route defined but the controller class cannot be found there are two options: 1. the controller class needs to be implemented or 2. the route is outdated and can be removed. If ?FooController? was found and ?BarController? is missing for the following example, either the controller should be implemented or the route should be removed: $app->group(['as' => 'foo', 'prefix' => 'foo', 'namespace' => 'Foo'], function($app) {
$app->group(['as' => 'foo', 'prefix' => 'foo'], function($app) {
$app->get('/all/{from}/{to}', ['as' => 'all', 'uses' => 'FooController@getFoo']);
$app->get('/all/{from}/{to}', ['as' => 'all', 'uses' => 'BarController@getBar']);
});
});
![]() |
|||||
117 | ]); |
||||
118 | 11 | $router->get('logout', [ |
|||
119 | 11 | 'uses' => '\Enomotodev\LaractiveAdmin\Http\Controllers\Auth\LoginController@logout', |
|||
0 ignored issues
–
show
The controller
App\Http\Controllers\\En...rs\Auth\LoginController does not seem to exist.
If there is a route defined but the controller class cannot be found there are two options: 1. the controller class needs to be implemented or 2. the route is outdated and can be removed. If ?FooController? was found and ?BarController? is missing for the following example, either the controller should be implemented or the route should be removed: $app->group(['as' => 'foo', 'prefix' => 'foo', 'namespace' => 'Foo'], function($app) {
$app->group(['as' => 'foo', 'prefix' => 'foo'], function($app) {
$app->get('/all/{from}/{to}', ['as' => 'all', 'uses' => 'FooController@getFoo']);
$app->get('/all/{from}/{to}', ['as' => 'all', 'uses' => 'BarController@getBar']);
});
});
![]() |
|||||
120 | 'as' => 'admin.logout', |
||||
121 | ]); |
||||
122 | 11 | }); |
|||
123 | |||||
124 | 11 | \Illuminate\Database\Eloquent\Builder::macro('comments', function () { |
|||
125 | 4 | return $this->getModel()->morphMany(LaractiveAdminComment::class, 'commentable'); |
|||
0 ignored issues
–
show
The method
getModel() does not exist on Enomotodev\LaractiveAdmin\ServiceProvider .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
126 | 11 | }); |
|||
127 | 11 | } |
|||
128 | |||||
129 | /** |
||||
130 | * Register a service provider with the application. |
||||
131 | * |
||||
132 | * @return void |
||||
133 | */ |
||||
134 | 11 | public function register() |
|||
135 | { |
||||
136 | 11 | $this->mergeConfigFrom($this->configPath(), 'laractive-admin'); |
|||
137 | |||||
138 | 11 | $this->app->register(HtmlServiceProvider::class); |
|||
139 | 11 | $this->app->register(HttpauthServiceProvider::class); |
|||
140 | |||||
141 | 11 | $this->app->alias('Form', FormFacade::class); |
|||
142 | 11 | $this->app->alias('Html', HtmlFacade::class); |
|||
143 | |||||
144 | 11 | $this->app->singleton(Menu::class); |
|||
145 | |||||
146 | 11 | $this->app['config']['auth.guards'] += [ |
|||
147 | 'laractive-admin' => [ |
||||
148 | 'driver' => 'session', |
||||
149 | 'provider' => 'admin_users', |
||||
150 | ], |
||||
151 | ]; |
||||
152 | 11 | $this->app['config']['auth.providers'] += [ |
|||
153 | 'admin_users' => [ |
||||
154 | 'driver' => 'eloquent', |
||||
155 | 'model' => AdminUser::class, |
||||
156 | ], |
||||
157 | ]; |
||||
158 | |||||
159 | 11 | $this->getRouter()->aliasMiddleware('laractive-admin', LaractiveAdminAuthenticate::class); |
|||
160 | 11 | $this->getRouter()->aliasMiddleware('httpauth', HttpauthAuthenticate::class); |
|||
161 | 11 | $this->getRouter()->aliasMiddleware('sharing-data', SharingDataWithAllViews::class); |
|||
162 | |||||
163 | 11 | $this->app->singleton('command.laractive-admin.install', function ($app) { |
|||
164 | 11 | return new InstallCommand($app['files'], $app['composer']); |
|||
165 | 11 | }); |
|||
166 | 11 | $this->app->singleton('command.laractive-admin.uninstall', function ($app) { |
|||
167 | 11 | return new UninstallCommand($app['files'], $app['composer']); |
|||
168 | 11 | }); |
|||
169 | 11 | $this->app->singleton('command.laractive-admin.seed', function () { |
|||
170 | 11 | return new SeedCommand; |
|||
171 | 11 | }); |
|||
172 | 11 | $this->app->singleton('httpauth', function ($app) { |
|||
173 | return new Httpauth($app['config']->get('laractive-admin.httpauth')); |
||||
174 | 11 | }); |
|||
175 | |||||
176 | 11 | $this->commands(['command.laractive-admin.install']); |
|||
177 | 11 | $this->commands(['command.laractive-admin.uninstall']); |
|||
178 | 11 | $this->commands(['command.laractive-admin.seed']); |
|||
179 | 11 | } |
|||
180 | |||||
181 | /** |
||||
182 | * @return string |
||||
183 | */ |
||||
184 | 11 | protected function configPath() |
|||
185 | { |
||||
186 | 11 | return __DIR__.'/../config/laractive-admin.php'; |
|||
187 | } |
||||
188 | |||||
189 | /** |
||||
190 | * Get the active router. |
||||
191 | * |
||||
192 | * @return \Illuminate\Routing\Router |
||||
193 | */ |
||||
194 | 11 | protected function getRouter() |
|||
195 | { |
||||
196 | 11 | return $this->app['router']; |
|||
197 | } |
||||
198 | |||||
199 | /** |
||||
200 | * Get the filesystem. |
||||
201 | * |
||||
202 | * @return \Illuminate\Filesystem\Filesystem |
||||
203 | */ |
||||
204 | 11 | protected function getFilesystem() |
|||
205 | { |
||||
206 | 11 | return $this->app['files']; |
|||
207 | } |
||||
208 | } |
||||
209 |
If there is a route defined but the controller class cannot be found there are two options: 1. the controller class needs to be implemented or 2. the route is outdated and can be removed.
If ?FooController? was found and ?BarController? is missing for the following example, either the controller should be implemented or the route should be removed: