diff --git a/src/Events/EventWatcher.php b/src/Events/EventWatcher.php new file mode 100644 index 00000000..edc53de6 --- /dev/null +++ b/src/Events/EventWatcher.php @@ -0,0 +1,40 @@ +broadcastOn(); + + // Only events dispatched on the nativephp channel + if(! in_array('nativephp', $channels)) { + return; + } + + // Only post custom events to broadcasting endpoint + if(str_starts_with($eventName ,'Native\\Laravel\\Events')) { + return; + } + + $this->client->post('broadcast', [ + 'event' => "\\{$eventName}", + 'payload' => $event + ]); + }); + } +} diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index 609cf421..2f618eed 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -11,6 +11,7 @@ use Native\Laravel\Commands\MinifyApplicationCommand; use Native\Laravel\Commands\SeedDatabaseCommand; use Native\Laravel\Logging\LogWatcher; +use Native\Laravel\Events\EventWatcher; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -61,6 +62,8 @@ protected function configureApp() app(LogWatcher::class)->register(); } + app(EventWatcher::class)->register(); + $this->rewriteStoragePath(); $this->rewriteDatabase();