3
3
namespace BeyondCode \LaravelWebSockets ;
4
4
5
5
use BeyondCode \LaravelWebSockets \Dashboard \EventSubscriber ;
6
+ use BeyondCode \LaravelWebSockets \Dashboard \Http \Controllers \AuthenticateDashboard ;
7
+ use BeyondCode \LaravelWebSockets \Dashboard \Http \Controllers \SendMessage ;
8
+ use BeyondCode \LaravelWebSockets \Dashboard \Http \Controllers \ShowDashboard ;
9
+ use BeyondCode \LaravelWebSockets \Dashboard \Http \Middleware \Authorize ;
6
10
use Illuminate \Support \Facades \Event ;
7
11
use Illuminate \Support \Facades \Gate ;
8
12
use Illuminate \Support \Facades \Route ;
@@ -14,13 +18,11 @@ class WebSocketsServiceProvider extends ServiceProvider
14
18
{
15
19
public function boot ()
16
20
{
17
- Route::middlewareGroup ('websockets ' , config ('websockets.dashboard.middleware ' , []));
18
-
19
21
$ this ->publishes ([
20
22
__DIR__ .'/../config/websockets.php ' => base_path ('config/websockets.php ' ),
21
23
], 'config ' );
22
24
23
- $ this ->registerRoutes ();
25
+ $ this ->registerRouteMacro ();
24
26
25
27
$ this ->registerDashboardGate ();
26
28
@@ -33,21 +35,17 @@ public function boot()
33
35
Event::subscribe (EventSubscriber::class);
34
36
}
35
37
36
- protected function registerRoutes ()
38
+ protected function registerRouteMacro ()
37
39
{
38
- Route::group ($ this ->routeConfiguration (), function () {
39
- $ this ->loadRoutesFrom (__DIR__ .'/Dashboard/Http/routes.php ' );
40
+ Route::macro ('websocketsDashboard ' , function ($ prefix = 'websockets ' ) {
41
+ Route::prefix ($ prefix )->namespace ('\\' )->middleware (Authorize::class)->group (function () {
42
+ Route::get ('/ ' , ShowDashboard::class);
43
+ Route::post ('auth ' , AuthenticateDashboard::class);
44
+ Route::post ('event ' , SendMessage::class);
45
+ });
40
46
});
41
47
}
42
48
43
- protected function routeConfiguration ()
44
- {
45
- return [
46
- 'prefix ' => config ('websockets.dashboard.path ' ),
47
- 'middleware ' => 'websockets ' ,
48
- ];
49
- }
50
-
51
49
public function register ()
52
50
{
53
51
$ this ->mergeConfigFrom (__DIR__ .'/../config/websockets.php ' , 'websockets ' );
0 commit comments