Broadcasts / websockets

This commit is contained in:
David Bomba 2023-03-17 10:08:45 +11:00
parent 05829451b3
commit f79bdf141b
2 changed files with 19 additions and 4 deletions

View File

@ -23,7 +23,7 @@ use Illuminate\Queue\SerializesModels;
/** /**
* Class ClientWasArchived. * Class ClientWasArchived.
*/ */
class ClientWasArchived implements ShouldBroadcast class ClientWasArchived
{ {
use Dispatchable, InteractsWithSockets, SerializesModels; use Dispatchable, InteractsWithSockets, SerializesModels;
@ -56,7 +56,7 @@ class ClientWasArchived implements ShouldBroadcast
* @return Channel|array * @return Channel|array
*/ */
public function broadcastOn() public function broadcastOn()
{nlog("broadcasting"); {
return new PrivateChannel('channel-name'); return new PrivateChannel('channel-name');
} }
} }

View File

@ -14,13 +14,17 @@ namespace App\Events\Invoice;
use App\Models\Company; use App\Models\Company;
use App\Models\Invoice; use App\Models\Invoice;
use Illuminate\Queue\SerializesModels; 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 class InvoiceWasCreated implements ShouldBroadcast
{ {
use SerializesModels; use Dispatchable, InteractsWithSockets, SerializesModels;
/** /**
* @var Invoice * @var Invoice
@ -44,4 +48,15 @@ class InvoiceWasCreated
$this->company = $company; $this->company = $company;
$this->event_vars = $event_vars; $this->event_vars = $event_vars;
} }
/**
* Get the channels the event should broadcast on.
*
* @return PrivateChannel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
} }