A
A
Alex Walsh2021-07-31 20:11:37
Laravel
Alex Walsh, 2021-07-31 20:11:37

Laravel Websockets nothing happens when an event is called?

Good day!
If the event is called from the dashboard, then everything works, but if the dispatch method is called on the event in the controller, then nothing works.

The call from here works,
610585468d4c4631245634.png

but the call from the controller does not

public function index()
    {
        MyEvent::dispatch();
    }


The code of this event, everything is standard
<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class MyEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function broadcastOn()
    {
        return new Channel('channel');
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Walsh, 2021-08-01
@walsh_dev

Maybe it will help someone in the future, the solution was to implement the ShouldBroadcastNow interface instead of ShouldBroadcast. he throws them into the queue before running php artisan queue:work

class MyEvent implements ShouldBroadcastNow
{
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question