Mikolaj Marciniak
Mikolaj Marciniak

Reputation: 63

Why is Laravel & Pusher not working on localhost but works on production?

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));

enter image description here

Upvotes: 4

Views: 4818

Answers (3)

Thomas
Thomas

Reputation: 11

It works on localhost, there's one small detail a lot of people miss in Laravel's documentation: "Broadcasting is done via queues so that performance is not affected".

All you need to do is run php artisan queue:work and it'll magically work

Upvotes: 1

Tomjesch
Tomjesch

Reputation: 510

Check the .env file of your production application and set BROADCAST_DRIVER=log to BROADCAST_DRIVER=pusher.

Upvotes: 3

Mikolaj Marciniak
Mikolaj Marciniak

Reputation: 63

in config/broadcasting.php i just set the encrypted to false and it works!

Upvotes: 0

Related Questions