From 074bdc307d42e32482df02d5934c7f5b56e41a48 Mon Sep 17 00:00:00 2001 From: James Joffe Date: Sat, 6 Jul 2024 17:50:57 +1000 Subject: [PATCH] add global switch --- config/livewire-beacon.php | 11 +++++++++++ src/LivewireBeacon.php | 4 ++++ src/LivewireBeaconServiceProvider.php | 8 ++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/config/livewire-beacon.php b/config/livewire-beacon.php index db3ff62..921be76 100644 --- a/config/livewire-beacon.php +++ b/config/livewire-beacon.php @@ -2,6 +2,17 @@ return [ + /* + |-------------------------------------------------------------------------- + | Beacon Enabled + |-------------------------------------------------------------------------- + | + | This option controls whether or not Beacon is enabled. + | + */ + + 'enabled' => true, + /* |-------------------------------------------------------------------------- | Beacon Channel diff --git a/src/LivewireBeacon.php b/src/LivewireBeacon.php index f63fd41..358cc54 100755 --- a/src/LivewireBeacon.php +++ b/src/LivewireBeacon.php @@ -10,6 +10,10 @@ class LivewireBeacon public static function livewireBeaconScripts($expression) { + if (! config('livewire-beacon.enabled', true)) { + return; + } + return '{!! \Executable\LivewireBeacon\LivewireBeacon::scripts('.$expression.') !!}'; } diff --git a/src/LivewireBeaconServiceProvider.php b/src/LivewireBeaconServiceProvider.php index b2123f4..6ddf2c5 100644 --- a/src/LivewireBeaconServiceProvider.php +++ b/src/LivewireBeaconServiceProvider.php @@ -26,13 +26,17 @@ public function configurePackage(Package $package): void public function packageBooted() { + Blade::directive('livewireBeaconScripts', [LivewireBeacon::class, 'livewireBeaconScripts']); + + if (! config('livewire-beacon.enabled', true)) { + return; + } + Event::listen( MessageReceived::class, ReverbMessageReceivedListener::class, ); - Blade::directive('livewireBeaconScripts', [LivewireBeacon::class, 'livewireBeaconScripts']); - $route = Route::get( config('app.debug') ? '/livewire/beacon.js' : 'livewire/beacon.min.js', [LivewireBeacon::class, 'returnJavascriptAsFile']