---
title: "Typed reactions — Likes for Laravel | Roundly"
description: "Turn plain likes into typed reactions — love, wow, laugh or your own set — guarded by a config allowlist."
url: https://roundly-consulting.com/open-source/docs/likes-for-laravel/typed-reactions
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)

# Typed reactions

By default a single implicit like reaction is configured, so the package behaves as plain likes. Add more reaction types to config/likes.php to enable typed reactions:

```php
// config/likes.php
'reactions' => ['like', 'love', 'wow', 'laugh'],
'default_reaction' => 'like',
```

Then pick a type with as() on the facade, or pass it to any trait verb, check, count or scope:

```php
Likes::as('love')->like($post);
Likes::for($post)->likedBy($user, 'love');
Likes::for($post)->count('love');
Post::orderByLikesDesc('love')->get();

$user->like($post, 'love');        // the trait shorthand
$post->isLikedBy($user, 'love');
```

## Several reactions per actor

like() lets typed reactions co-exist — one row per actor, likeable and type:

```php
Likes::actor($user)->as('love')->like($post);
Likes::actor($user)->as('wow')->like($post);     // both reactions now co-exist
Likes::actor($user)->as('wow')->unlike($post);   // removes only the "wow"
```

Use react() instead when an actor should hold exactly one reaction per item (see Switching reactions).

## The allowlist

A type outside reactions throws InvalidReactionTypeException — and so does every untyped call if default\_reaction is missing from the list:

```php
use RoundlyConsulting\Likes\Exceptions\InvalidReactionTypeException;
use RoundlyConsulting\Likes\Facades\Likes;

try {
    Likes::actor($user)->as('angry')->like($post);
} catch (InvalidReactionTypeException $e) {
    // The reaction type [angry] is not allowed. Allowed types: [like, love, wow, laugh].
}
```

Validate user input against the same list before it reaches the package:

```php
use Illuminate\Validation\Rule;

$data = $request->validate([
    'reaction' => ['required', 'string', Rule::in(config('likes.reactions'))],
]);

Likes::actor($request->user())->as($data['reaction'])->react($post);
```

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