File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 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 1111use Native \Laravel \Commands \MinifyApplicationCommand ;
1212use Native \Laravel \Commands \SeedDatabaseCommand ;
1313use Native \Laravel \Logging \LogWatcher ;
14+ use Native \Laravel \Events \EventWatcher ;
1415use Spatie \LaravelPackageTools \Package ;
1516use Spatie \LaravelPackageTools \PackageServiceProvider ;
1617
@@ -61,6 +62,8 @@ protected function configureApp()
6162 app (LogWatcher::class)->register ();
6263 }
6364
65+ app (EventWatcher::class)->register ();
66+
6467 $ this ->rewriteStoragePath ();
6568
6669 $ this ->rewriteDatabase ();
You can’t perform that action at this time.
0 commit comments