|
23 | 23 | - [Defining Channel Classes](#defining-channel-classes) |
24 | 24 | - [Broadcasting Events](#broadcasting-events) |
25 | 25 | - [Only To Others](#only-to-others) |
| 26 | + - [Customizing The Connection](#customizing-the-connection) |
26 | 27 | - [Receiving Broadcasts](#receiving-broadcasts) |
27 | 28 | - [Listening For Events](#listening-for-events) |
28 | 29 | - [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 |
642 | 643 |
|
643 | 644 | var socketId = Echo.socketId(); |
644 | 645 |
|
| 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 | + |
645 | 681 | <a name="receiving-broadcasts"></a> |
646 | 682 | ## Receiving Broadcasts |
647 | 683 |
|
|
0 commit comments