From f79bdf141b243b02c5bb3bb7a3a178f3b546d23b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Mar 2023 10:08:45 +1100 Subject: [PATCH] Broadcasts / websockets --- app/Events/Client/ClientWasArchived.php | 4 ++-- app/Events/Invoice/InvoiceWasCreated.php | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/Events/Client/ClientWasArchived.php b/app/Events/Client/ClientWasArchived.php index 1e0788ca447c..77bf459da449 100644 --- a/app/Events/Client/ClientWasArchived.php +++ b/app/Events/Client/ClientWasArchived.php @@ -23,7 +23,7 @@ use Illuminate\Queue\SerializesModels; /** * Class ClientWasArchived. */ -class ClientWasArchived implements ShouldBroadcast +class ClientWasArchived { use Dispatchable, InteractsWithSockets, SerializesModels; @@ -56,7 +56,7 @@ class ClientWasArchived implements ShouldBroadcast * @return Channel|array */ public function broadcastOn() - {nlog("broadcasting"); + { return new PrivateChannel('channel-name'); } } diff --git a/app/Events/Invoice/InvoiceWasCreated.php b/app/Events/Invoice/InvoiceWasCreated.php index 4469427c177b..555dab1cb0a3 100644 --- a/app/Events/Invoice/InvoiceWasCreated.php +++ b/app/Events/Invoice/InvoiceWasCreated.php @@ -14,13 +14,17 @@ namespace App\Events\Invoice; use App\Models\Company; use App\Models\Invoice; use Illuminate\Queue\SerializesModels; +use Illuminate\Broadcasting\PrivateChannel; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; +use Illuminate\Broadcasting\InteractsWithSockets; /** * Class InvoiceWasCreated. */ -class InvoiceWasCreated +class InvoiceWasCreated implements ShouldBroadcast { - use SerializesModels; + use Dispatchable, InteractsWithSockets, SerializesModels; /** * @var Invoice @@ -44,4 +48,15 @@ class InvoiceWasCreated $this->company = $company; $this->event_vars = $event_vars; } + + /** + * Get the channels the event should broadcast on. + * + * @return PrivateChannel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } + }