---
title: "Events — Likes for Laravel | Roundly"
description: "Liked, Unliked and ReactionChanged fire only on real changes, one event per change — plus an optional persisted counter column."
url: https://roundly-consulting.com/open-source/docs/likes-for-laravel/events
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)

# Events

Idempotent no-ops — liking what’s already liked, unliking what isn’t — dispatch no events. On a real change the package fires exactly one event:

```php
use RoundlyConsulting\Likes\Events\Liked;

class NotifyAuthor
{
    public function handle(Liked $event): void
    {
        // $event->actor, $event->likeable, $event->type, $event->like
    }
}
```

| Event | When | Properties |
| --- | --- | --- |
| `Liked` | A like is created or restored | actor, likeable, type, like |
| `Unliked` | A like is removed | actor, likeable, type, like |
| `ReactionChanged` | A reaction is switched via react() | actor, likeable, from, to, like |

- A switch via react() fires only ReactionChanged — never Liked or Unliked. When react() collapses several reactions into one, it also fires Unliked for each extra reaction it removes.
- Concurrent requests can’t double-fire: only the request that actually changed a row dispatches its event.
- Bulk likeMany() / unlikeMany() fire one event per item that actually changed.

## Registering listeners

```php
use Illuminate\Support\Facades\Event;
use RoundlyConsulting\Likes\Events\Liked;
use RoundlyConsulting\Likes\Events\ReactionChanged;

// e.g. in AppServiceProvider::boot()
Event::listen(Liked::class, NotifyAuthor::class);

Event::listen(function (ReactionChanged $event): void {
    // $event->from, $event->to — a clean transition, never an unlike + like
});
```

The events use SerializesModels, so queued listeners work as usual.

## Optional: a persisted counter column

The package never adds columns to your own tables. For O(1) counts use withLikesCount() / loadCount('likes'), or maintain your own counter column with a small listener — for example a likes\_count column on the likeable:

```php
use RoundlyConsulting\Likes\Events\Liked;
use RoundlyConsulting\Likes\Events\Unliked;

class SyncLikesCounter
{
    public function increment(Liked $event): void
    {
        $event->likeable->increment('likes_count');
    }

    public function decrement(Unliked $event): void
    {
        $event->likeable->decrement('likes_count');
    }
}
```

```php
Event::listen(Liked::class, [SyncLikesCounter::class, 'increment']);
Event::listen(Unliked::class, [SyncLikesCounter::class, 'decrement']);
```

Register it yourself — the package does not auto-register it. A reaction switch fires neither Liked nor Unliked, and a react() that collapses several reactions fires Unliked for each one it removes, so the counter stays correct.

## 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)
