Skip to content

Commit 84dade0

Browse files
[8.x] Ability to specify the broadcaster to use when broadcasting an event (#7213)
* WIP * formatting Co-authored-by: Taylor Otwell <[email protected]>
1 parent c791a9c commit 84dade0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

broadcasting.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [Defining Channel Classes](#defining-channel-classes)
2424
- [Broadcasting Events](#broadcasting-events)
2525
- [Only To Others](#only-to-others)
26+
- [Customizing The Connection](#customizing-the-connection)
2627
- [Receiving Broadcasts](#receiving-broadcasts)
2728
- [Listening For Events](#listening-for-events)
2829
- [Leaving A Channel](#leaving-a-channel)
@@ -642,6 +643,41 @@ If you are not using a global Axios instance, you will need to manually configur
642643

643644
var socketId = Echo.socketId();
644645

646+
<a name="customizing-the-connection"></a>
647+
### Customizing The Connection
648+
649+
If your application interacts with multiple broadcast connections and you want to broadcast an event using a broadcaster other than your default, you may specify which connection to push an event to using the `via` method:
650+
651+
use App\Events\OrderShipmentStatusUpdated;
652+
653+
broadcast(new OrderShipmentStatusUpdated($update))->via('pusher');
654+
655+
Alternatively, you may specify the event's broadcast connection by calling the `broadcastVia` method within the event's constructor:
656+
657+
<?php
658+
659+
namespace App\Events;
660+
661+
use Illuminate\Broadcasting\Channel;
662+
use Illuminate\Broadcasting\InteractsWithSockets;
663+
use Illuminate\Broadcasting\PresenceChannel;
664+
use Illuminate\Broadcasting\PrivateChannel;
665+
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
666+
use Illuminate\Queue\SerializesModels;
667+
668+
class OrderShipmentStatusUpdated implements ShouldBroadcast
669+
{
670+
/**
671+
* Create a new event instance.
672+
*
673+
* @return void
674+
*/
675+
public function __construct()
676+
{
677+
$this->broadcastVia('pusher');
678+
}
679+
}
680+
645681
<a name="receiving-broadcasts"></a>
646682
## Receiving Broadcasts
647683

0 commit comments

Comments
 (0)