Now, to use web sockets, you need to inherit the ShouldBroadcast interface.
Interface ShouldBroadcast
When a user views one of his orders, he must show him status updates, without requiring to refresh the page. Instead, we will stream updates to the application as they are created. So, we need to mark the ShippingStatUUpdated event with the ShouldBroadcast interface. Thus, Laravel will understand that it is necessary to broadcast this event when it occurs:
<?php namespace App\Events; use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Broadcasting\PresenceChannel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; class ShippingStatusUpdated implements ShouldBroadcast { // }
The ShouldBroadcast interface requires that the broadcastOn () method be defined in the event. This method is responsible for returning the channels to which the event should be broadcast. In the generated event classes, an empty preset of this method is already defined, we just have to fill it. We need the order creator to be able to view status updates, so we will broadcast the event to a private channel tied to the order:
/** * Получить каналы, на которые надо вещать событие. * * @return array */ public function broadcastOn() { return new PrivateChannel('order.'.$this->update->order_id); }
Full article here: https://laravel.ru/docs/v5/broadcasting