I can not deal with web sockets in Laravel 5.4.

In Laravel to version 5.4, when creating an event, these events are inherited from the Events class and when working with sockets, the transmitted data was listened to and sent, and starting from Laravel 5.4, these events are not inherited from the events class. When you try to get data sent from one client to another, nothing happens, such as there is no listener or there may be another reason, and when you specify inheritance, errors are knocked out and, accordingly, sockets do not work. Tell me pliz how to do it the most elementary chat between two users on Laravel 5.4 version?

    1 answer 1

    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