0

I am using pusher as broadcast driver. My requirement is, I want to broadcast to the same channel (orders) from different events. For that I have two events OrderCreatedEvent and OrderUpdatedEvent

OrderCreatedEvent

class OrderCreatedEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    private Order $order;

    public function __construct(Order $order)
    {
        $this->order = $order;

    }

    
    public function broadcastOn()
    {
        return new PrivateChannel('orders');
    }

    public function broadcastAs()
    {
        return 'OrderCreatedEvent';
    }

    public function broadcastWith()
    {
        return [
            'id' => $this->order->id,
            'amount' => $this->order->amount
        ];
    }
}

OrderUpdatedEvent

class OrderUpdatedEvent implements ShouldBroadcastNow
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    private Order $order;

    public function __construct(Order $order)
    {
        $this->order = $order;

    }

    
    public function broadcastOn()
    {
        return new PrivateChannel('orders');
    }

    public function broadcastAs()
    {
        return 'OrderCreatedEvent';
    }

    public function broadcastWith()
    {
        return [
            'id' => $this->order->id,
            'amount' => $this->order->amount
        ];
    }
}

channels.php

Broadcast::channel('orders', function ($user) {
    return Auth::check();
});

Problem: As you can see, I am broadcasting to channel orders from OrderCreatedEvent and OrderUpdatedEvent. It is working fine locally, but it is not working on the server. I can see the broadcast on pusher portal if the event is broadcasted from localhost.

Trying to fix and understand the reason. Any help is highly appreciated.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Ahmar Arshad
  • 477
  • 1
  • 10
  • 22
  • Have you tried changing the config: 'useTLS' => env('PUSHER_SCHEME', 'https') === 'https': broadcasting.php ? – Ali Raza Oct 10 '22 at 04:43

0 Answers0