I have Laravel Echo set up successfully to listen to one event. However, when I tried to add an additional event to the same channel the first one was a part of, the client-side seemingly does not recognize this new event. However, looking at Laravel Horizon, I can see the jobs being registered and processed successfully. Any ideas on why this may be occurring?
Event:
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class ParticipantCreated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $data;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($data)
{
$this->$data = $data;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channelReceiveLiveData');
}
}
Controller where event is being emitted:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Participant;
use App\Test;
use App\Events\ParticipantCreated;
class ParticipantController extends Controller
{
public function create() {
event(new ParticipantCreated('test'));
}
}
VueJS component where Echo is setup:
// This one works
Echo.channel('channelReceiveLiveData')
.listen('liveDataTrigger', (e) => {
console.log('Received Live Event');
})
// This one does not work
.listen('ParticipantCreated', (e) => {
console.log('Received Participant Created');
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire