Answer the question
In order to leave comments, you need to log in
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,
but the call from the controller does not
public function index()
{
MyEvent::dispatch();
}
<?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
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 questionAsk a Question
731 491 924 answers to any question