diff --git a/app/Events/LongRunPrivateJobDone.php b/app/Events/LongRunPrivateJobDone.php new file mode 100644 index 0000000..f52c355 --- /dev/null +++ b/app/Events/LongRunPrivateJobDone.php @@ -0,0 +1,39 @@ +id = $id; + $this->message = $message; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('App.User.'.$this->id); + } +} diff --git a/app/Jobs/LongRunPrivateJob.php b/app/Jobs/LongRunPrivateJob.php new file mode 100644 index 0000000..6517ad7 --- /dev/null +++ b/app/Jobs/LongRunPrivateJob.php @@ -0,0 +1,35 @@ +id = $id; + } + + public function handle() + { + $seconds = 5; + sleep($seconds); + + $link = 'here'; + event(new LongRunPrivateJobDone( + $this->id, + 'Long run private job (for '.$this->id.') done after '.$seconds.' seconds. Please check '.$link.'.') + ); + info('Long run private job (for '.$this->id.') done after '.$seconds.' seconds. Please check '.$link.'.'); + } +} diff --git a/config/app.php b/config/app.php index 8409e00..33aa202 100644 --- a/config/app.php +++ b/config/app.php @@ -171,7 +171,7 @@ return [ */ App\Providers\AppServiceProvider::class, App\Providers\AuthServiceProvider::class, - // App\Providers\BroadcastServiceProvider::class, + App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index c5b0647..1045e71 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -5,7 +5,7 @@
-
{{ __('Dashboard') }}
+
{{ __('Dashboard') }} auth user: {{ auth()->id() }}
@if (session('status')) @@ -17,6 +17,7 @@ {{ __('You are logged in!') }}
Run a long job + Run a long private job
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 6a6a401..dadd082 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -93,6 +93,15 @@ timeout: false }); }); + Echo.private('App.User.{{ auth()->id() }}') + .listen('LongRunPrivateJobDone', (e) => { + noty({ + type: 'success', + layout: 'bottomRight', + text: e.message, + timeout: false + }); + }); @if (Session::has('flash_notification.message'))