I'm making a little dating app where I use Pusher and Laravel. I use an event called NewMessage
and listening on channel msg.{userId}
. Listening works, however broadcasting events doesn't. It works on production though.
My code is as follows:
NewMessage.php
public function __construct(Message $message, $toUserId, $conversation)
{
//
$this->message = $message;
$this->toUserId = $toUserId;
$this->conversation = $conversation;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('msg.'.$this->toUserId);
}
public function broadcastAs()
{
return 'NewMessage';
}
ConversationController.php
event(new NewMessage($message, $toUserId, $conversation));