1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelFlare\Flare\Providers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Routing\Router; |
6
|
|
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; |
7
|
|
|
|
8
|
|
|
class RouteServiceProvider extends ServiceProvider |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* This namespace is applied to the controller routes in your routes file. |
12
|
|
|
* |
13
|
|
|
* In addition, it is set as the URL generator's root namespace. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $namespace = '\LaravelFlare\Flare\Http\Controllers'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Define your route model bindings, pattern filters, etc. |
21
|
|
|
* |
22
|
|
|
* @param \Illuminate\Routing\Router $router |
23
|
|
|
*/ |
24
|
|
|
public function boot(Router $router) |
25
|
|
|
{ |
26
|
|
|
// |
27
|
|
|
|
28
|
|
|
parent::boot($router); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Define the routes for the application. |
33
|
|
|
* |
34
|
|
|
* @param \Illuminate\Routing\Router $router |
35
|
|
|
*/ |
36
|
|
|
public function map(Router $router) |
37
|
|
|
{ |
38
|
|
|
$this->registerMiddleware($router); |
39
|
|
|
$this->registerDefinedRoutes($router); |
40
|
|
|
$this->registerDefaultRoutes($router); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Register all the Flare Provided Middleware and Middleware Groups. |
45
|
|
|
* |
46
|
|
|
* We define flarebase rather than extend an existing middleware stack |
47
|
|
|
* since it is possible that a user has amended the default middleware |
48
|
|
|
* of their application in a way that could break Flare. |
49
|
|
|
* |
50
|
|
|
* @param Router $router |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
protected function registerMiddleware(Router $router) |
55
|
|
|
{ |
56
|
|
|
$router->middleware('flareauthenticate', \LaravelFlare\Flare\Http\Middleware\FlareAuthenticate::class); |
57
|
|
|
$router->middleware('checkmodelfound', \LaravelFlare\Flare\Http\Middleware\CheckModelFound::class); |
58
|
|
|
$router->middleware('checkpermissions', \LaravelFlare\Flare\Http\Middleware\CheckPermissions::class); |
59
|
|
|
|
60
|
|
|
$router->middlewareGroup('flarebase', [ |
61
|
|
|
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, |
62
|
|
|
\Illuminate\Session\Middleware\StartSession::class, |
63
|
|
|
\Illuminate\View\Middleware\ShareErrorsFromSession::class, |
64
|
|
|
\App\Http\Middleware\VerifyCsrfToken::class, |
65
|
|
|
\App\Http\Middleware\EncryptCookies::class, |
66
|
|
|
]); |
67
|
|
|
|
68
|
|
|
$router->middlewareGroup('flare', [ |
69
|
|
|
'flarebase', |
70
|
|
|
'flareauthenticate', |
71
|
|
|
'checkpermissions', |
72
|
|
|
]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Register the Defined Routes. |
77
|
|
|
* |
78
|
|
|
* This registers all the routes which have been defined by |
79
|
|
|
* Admin sections defined in the Application's Flare Config |
80
|
|
|
* (or in the runtime config if anotehr service provider |
81
|
|
|
* has already started manipulating these dynamically). |
82
|
|
|
* |
83
|
|
|
* @param Router $router |
84
|
|
|
* |
85
|
|
|
* @return void |
86
|
|
|
*/ |
87
|
|
|
protected function registerDefinedRoutes(Router $router) |
88
|
|
|
{ |
89
|
|
|
$router->group( |
90
|
|
|
[ |
91
|
|
|
'prefix' => \Flare::config('admin_url'), |
92
|
|
|
'as' => 'flare::', |
93
|
|
|
'middleware' => ['flare'] |
94
|
|
|
], |
95
|
|
|
function ($router) { |
96
|
|
|
\Flare::admin()->registerRoutes($router); |
97
|
|
|
$router->get('/', $this->namespace.'\AdminController@getDashboard')->name('dashboard'); |
98
|
|
|
} |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Register the Default Routes. |
104
|
|
|
* |
105
|
|
|
* This registers all the default routes which are included |
106
|
|
|
* with Flare. These consist of things which will probably |
107
|
|
|
* be included with every application such as the login, |
108
|
|
|
* logout and password reset forms. |
109
|
|
|
* |
110
|
|
|
* The login form can however be hidden by setting the |
111
|
|
|
* 'show' config for 'login' to false. |
112
|
|
|
* |
113
|
|
|
* @param Router $router |
114
|
|
|
* |
115
|
|
|
* @return void |
116
|
|
|
*/ |
117
|
|
|
protected function registerDefaultRoutes(Router $router) |
118
|
|
|
{ |
119
|
|
|
$router->group( |
120
|
|
|
[ |
121
|
|
|
'prefix' => \Flare::config('admin_url'), |
122
|
|
|
'as' => 'flare::', |
123
|
|
|
'middleware' => ['flarebase'] |
124
|
|
|
], |
125
|
|
|
function ($router) { |
126
|
|
|
$router->get('index', $this->namespace.'\AdminController@getIndex')->name('index'); |
127
|
|
|
|
128
|
|
|
if (\Flare::show('login')) { |
129
|
|
|
$router->get('login', $this->namespace.'\AdminController@getLogin')->name('login'); |
130
|
|
|
$router->post('login', $this->namespace.'\AdminController@postLogin')->name('login'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$router->get('logout', $this->namespace.'\AdminController@getLogout')->name('logout'); |
134
|
|
|
$router->get('reset', $this->namespace.'\AdminController@getReset')->name('reset'); |
135
|
|
|
} |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|