---
title: "Broadcasting — Likes for Laravel | Roundly"
description: "Opt-in broadcasting of Liked, Unliked and ReactionChanged over Laravel Echo on likes.{morph}.{id} channels."
url: https://roundly-consulting.com/open-source/docs/likes-for-laravel/broadcasting
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Likes for Laravel](https://roundly-consulting.com/open-source/docs/likes-for-laravel.md)

# Broadcasting

Liked, Unliked and ReactionChanged can broadcast over Laravel Echo. Broadcasting is off by default, so existing installs are unaffected. Enable it in config/likes.php or the environment:

```php
// config/likes.php
'broadcast' => [
    'enabled' => env('LIKES_BROADCAST', true),
    'channel_prefix' => 'likes',
    'channel_type' => 'private',   // private | public | presence
],
```

```bash
LIKES_BROADCAST=true
```

When enabled, each event broadcasts on {channel\_prefix}.{segment}.{id}, where the segment is the likeable’s full morph class with its backslashes turned into dots, as Laravel’s model broadcasting does — or its morph-map alias as-is. App\\Models\\Post id 42 broadcasts on likes.App.Models.Post.42, or on likes.post.42 with Relation::morphMap(\['post' => Post::class\]). The events keep dispatching as plain events for your listeners regardless of this setting.

| Event | Broadcast as |
| --- | --- |
| `Liked` | `like.created` |
| `Unliked` | `like.removed` |
| `ReactionChanged` | `reaction.changed` |

## Authorising private channels

The default channel type is private, so authorise it in routes/channels.php:

```php
// routes/channels.php
use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('likes.App.Models.Post.{id}', function ($user, int $id): bool {
    return $user->can('view', Post::findOrFail($id));
});
```

## Listening with Echo

Because the events use custom broadcast names, prefix them with a dot in Echo:

```js
Echo.private('likes.App.Models.Post.42')
    .listen('.like.created', (e) => { /* e.like_id, e.actor_type, e.actor_id, e.likeable_type, e.likeable_id, e.type */ })
    .listen('.like.removed', (e) => { /* ... */ })
    .listen('.reaction.changed', (e) => { /* e.from, e.to */ });
```

## Delivery & payload

The events implement ShouldBroadcast, so broadcasts go through your queue. The payload carries ids and the reaction only — never the actor or likeable models, so no attribute of your users ever reaches a channel subscriber:

```php
// like.created / like.removed
['like_id' => 7, 'actor_type' => 'User', 'actor_id' => 1,
 'likeable_type' => 'Post', 'likeable_id' => 42, 'type' => 'love']

// reaction.changed — `from` / `to` instead of `type`
[..., 'from' => 'like', 'to' => 'love']
```

actor\_type and likeable\_type are the model’s class basename (User, Post) — never a PHP class name, and not the morph-map alias either, with or without a morph map. Before 1.1.2, an app without a morph map sent App\\Models\\User to every subscriber — update listeners that matched the old value. They only label the payload: the channel name still identifies the likeable and stays as it was (likes.App.Models.Post.42). Same-named models in different namespaces (Blog\\Post, Forum\\Post) share a basename, so a listener that needs to tell them apart goes by the channel it subscribed to.

Load anything else you need client-side by id.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/likes-for-laravel.md)
