How do you know that there are 2 messages send? I don't see anything strange in your code.
Nov 30, 2019
6
Level 6
laravel broadcast with pusher sends messages twice
event.php
public $newTask;
public function __construct($newTask)
{
$this->newTask = $newTask;
$this->dontBroadcastToCurrentUser();
}
public function broadcastOn()
{
return new PrivateChannel('user-' . Auth::id() . '-tasks');
}
channels.php
Broadcast::channel('user-' . Auth::id() . '-tasks', function ($user, $id)
{
if ($user->name == "tamara")
return true;
});
bootstrap.js
window.Echo.private('user-' + this.user_id + '-tasks')
.listen('NewTaskAdded', e => {
console.log("new task");
console.log(e);
});
and i just called this ones
controller.php
NewTaskAdded::dispatch("test");
but pusher is receiving to messages and sends it to users
Please or to participate in this conversation.