13
13
use BeyondCode \LaravelWebSockets \Statistics \Http \Middleware \Authorize as AuthorizeStatistics ;
14
14
use BeyondCode \LaravelWebSockets \WebSockets \Channels \ChannelManager ;
15
15
use BeyondCode \LaravelWebSockets \WebSockets \Channels \ChannelManagers \ArrayChannelManager ;
16
+ use Illuminate \Database \QueryException ;
16
17
use Illuminate \Support \Facades \Gate ;
17
18
use Illuminate \Support \Facades \Route ;
18
19
use Illuminate \Support \Facades \Schema ;
@@ -23,52 +24,62 @@ class WebSocketsServiceProvider extends ServiceProvider
23
24
public function boot ()
24
25
{
25
26
$ this ->publishes ([
26
- __DIR__ . '/../config/websockets.php ' => base_path ('config/websockets.php ' ),
27
+ __DIR__ . '/../config/websockets.php ' => base_path ('config/websockets.php ' ),
27
28
], 'config ' );
28
29
29
- if (! Schema::hasTable ('websockets_statistics_entries ' )) {
30
- $ this ->publishes ([
31
- __DIR__ .'/../database/migrations/create_websockets_statistics_entries_table.php.stub ' => database_path ('migrations/ ' .date ('Y_m_d_His ' , time ()).'_create_websockets_statistics_entries_table.php ' ),
32
- ], 'migrations ' );
30
+ try {
31
+ if (!Schema::hasTable ('websockets_statistics_entries ' )) {
32
+ $ this ->publishes ([
33
+ __DIR__ . '/../database/migrations/create_websockets_statistics_entries_table.php.stub ' => database_path ('migrations/ ' . date ('Y_m_d_His ' , time ()) . '_create_websockets_statistics_entries_table.php ' ),
34
+ ], 'migrations ' );
35
+ }
36
+
37
+ $ this
38
+ ->registerRoutes ()
39
+ ->registerDashboardGate ();
40
+
41
+ $ this ->loadViewsFrom (__DIR__ . '/../resources/views/ ' , 'websockets ' );
42
+
43
+ $ this ->commands ([
44
+ Console \StartWebSocketServer::class,
45
+ Console \CleanStatistics::class,
46
+ Console \RestartWebSocketServer::class,
47
+ ]);
48
+ } catch (QueryException $ e ) {
49
+ // Exception raised by composer update
50
+ // Usually happens when doing on CI where no DB exists at start
51
+ // Either way if DB connection not obtained
52
+ // Catching and doing nothing is ignore for composer update
33
53
}
34
-
35
- $ this
36
- ->registerRoutes ()
37
- ->registerDashboardGate ();
38
-
39
- $ this ->loadViewsFrom (__DIR__ .'/../resources/views/ ' , 'websockets ' );
40
-
41
- $ this ->commands ([
42
- Console \StartWebSocketServer::class,
43
- Console \CleanStatistics::class,
44
- Console \RestartWebSocketServer::class,
45
- ]);
46
54
}
47
55
48
56
public function register ()
49
57
{
50
- $ this ->mergeConfigFrom (__DIR__ . '/../config/websockets.php ' , 'websockets ' );
58
+ $ this ->mergeConfigFrom (__DIR__ . '/../config/websockets.php ' , 'websockets ' );
51
59
52
60
$ this ->app ->singleton ('websockets.router ' , function () {
53
61
return new Router ();
54
62
});
55
63
56
64
$ this ->app ->singleton (ChannelManager::class, function () {
57
65
return config ('websockets.channel_manager ' ) !== null && class_exists (config ('websockets.channel_manager ' ))
58
- ? app (config ('websockets.channel_manager ' )) : new ArrayChannelManager ();
66
+ ? app (config ('websockets.channel_manager ' )) : new ArrayChannelManager ();
59
67
});
60
68
61
69
$ this ->app ->singleton (AppProvider::class, function () {
62
70
return app (config ('websockets.app_provider ' ));
63
71
});
64
72
}
65
73
74
+ /**
75
+ * @return mixed
76
+ */
66
77
protected function registerRoutes ()
67
78
{
68
79
Route::prefix (config ('websockets.path ' ))->group (function () {
69
80
Route::middleware (config ('websockets.middleware ' , [AuthorizeDashboard::class]))->group (function () {
70
81
Route::get ('/ ' , ShowDashboard::class);
71
- Route::get ('/api/{appId}/statistics ' , [DashboardApiController::class, 'getStatistics ' ]);
82
+ Route::get ('/api/{appId}/statistics ' , [DashboardApiController::class, 'getStatistics ' ]);
72
83
Route::post ('auth ' , AuthenticateDashboard::class);
73
84
Route::post ('event ' , SendMessage::class);
74
85
});
@@ -81,6 +92,9 @@ protected function registerRoutes()
81
92
return $ this ;
82
93
}
83
94
95
+ /**
96
+ * @return mixed
97
+ */
84
98
protected function registerDashboardGate ()
85
99
{
86
100
Gate::define ('viewWebSocketsDashboard ' , function ($ user = null ) {
0 commit comments