Laravel - Broadcasting - Model Broadcasting Channel Conventions

As you may have noticed, the broadcastOn method in the model example above did not return Channel instances. Instead, Eloquent models were returned directly. If an Eloquent model instance is returned by your model's broadcastOn method (or is contained in an array returned by the method), Laravel will automatically instantiate a private channel instance for the model using the model's class name and primary key identifier as the channel name.

So, an App\Models\User model with an id of 1 would be converted into a Illuminate\Broadcasting\PrivateChannel instance with a name of App.Models.User.1. Of course, in addition to returning Eloquent model instances from your model's broadcastOn method, you may return complete Channel instances in order to have full control over the model's channel names:

    use Illuminate\Broadcasting\PrivateChannel;
     * Get the channels that model events should broadcast on.
     * @param  string  $event
     * @return \Illuminate\Broadcasting\Channel|array
    public function broadcastOn($event)
        return [new PrivateChannel('user.'.$this->id)];

If you plan to explicitly return a channel instance from your model's broadcastOn method, you may pass an Eloquent model instance to the channel's constructor. When doing so, Laravel will use the model channel conventions discussed above to convert the Eloquent model into a channel name string:

    return [new Channel($this->user)];

If you need to determine the channel name of a model, you may call the broadcastChannel method on any model instance. For example, this method returns the string App.Models.User.1 for a App\Models\User model with an id of 1: