File tree 2 files changed +43
-0
lines changed
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Native \Laravel \Events ;
4
+
5
+ use Illuminate \Support \Facades \Event ;
6
+ use Native \Laravel \Client \Client ;
7
+
8
+ class EventWatcher
9
+ {
10
+ public function __construct (protected Client $ client ) {}
11
+
12
+ public function register (): void
13
+ {
14
+ Event::listen ('* ' , function (string $ eventName , array $ data ) {
15
+
16
+ $ event = $ data [0 ] ?? null ;
17
+
18
+ if (! method_exists ($ event , 'broadcastOn ' )) {
19
+ return ;
20
+ }
21
+
22
+ $ channels = $ event ->broadcastOn ();
23
+
24
+ // Only events dispatched on the nativephp channel
25
+ if (! in_array ('nativephp ' , $ channels )) {
26
+ return ;
27
+ }
28
+
29
+ // Only post custom events to broadcasting endpoint
30
+ if (str_starts_with ($ eventName ,'Native \\Laravel \\Events ' )) {
31
+ return ;
32
+ }
33
+
34
+ $ this ->client ->post ('broadcast ' , [
35
+ 'event ' => "\\{$ eventName }" ,
36
+ 'payload ' => $ event
37
+ ]);
38
+ });
39
+ }
40
+ }
Original file line number Diff line number Diff line change 11
11
use Native \Laravel \Commands \MinifyApplicationCommand ;
12
12
use Native \Laravel \Commands \SeedDatabaseCommand ;
13
13
use Native \Laravel \Logging \LogWatcher ;
14
+ use Native \Laravel \Events \EventWatcher ;
14
15
use Spatie \LaravelPackageTools \Package ;
15
16
use Spatie \LaravelPackageTools \PackageServiceProvider ;
16
17
@@ -61,6 +62,8 @@ protected function configureApp()
61
62
app (LogWatcher::class)->register ();
62
63
}
63
64
65
+ app (EventWatcher::class)->register ();
66
+
64
67
$ this ->rewriteStoragePath ();
65
68
66
69
$ this ->rewriteDatabase ();
You can’t perform that action at this time.
0 commit comments