InteractsWithBroadcasting.php
TLDR
This file is a trait called InteractsWithBroadcasting
that provides methods for broadcasting events using specific broadcasters.
Methods
broadcastVia
This method allows you to broadcast an event using a specific broadcaster. It takes an optional parameter $connection
which specifies the broadcaster connection to be used. If $connection
is null
, the method sets the broadcastConnection
property to [null]
. Otherwise, it wraps the $connection
value using the Arr::wrap()
method, and assigns the result to the broadcastConnection
property. The method returns the instance of the class.
broadcastConnections
This method returns an array containing the broadcaster connections that the event should be broadcast on.
<?php
namespace Illuminate\Broadcasting;
use Illuminate\Support\Arr;
trait InteractsWithBroadcasting
{
/**
* The broadcaster connection to use to broadcast the event.
*
* @var array
*/
protected $broadcastConnection = [null];
/**
* Broadcast the event using a specific broadcaster.
*
* @param array|string|null $connection
* @return $this
*/
public function broadcastVia($connection = null)
{
$this->broadcastConnection = is_null($connection)
? [null]
: Arr::wrap($connection);
return $this;
}
/**
* Get the broadcaster connections the event should be broadcast on.
*
* @return array
*/
public function broadcastConnections()
{
return $this->broadcastConnection;
}
}