NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Likes for Laravel

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:

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

When enabled, each event broadcasts on {channel_prefix}.{segment}.{id}, where the segment is the likeable’s morph class — last segment only, snake_cased and pluralised. App\Models\Post id 42 broadcasts on likes.posts.42. The events keep dispatching as plain events for your listeners regardless of this setting.

EventBroadcast as
Likedlike.created
Unlikedlike.removed
ReactionChangedreaction.changed

Authorising private channels

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

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

Broadcast::channel('likes.posts.{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:

Echo.private('likes.posts.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:

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

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

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

By donating, you agree to our donation terms.

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.