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

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:

// 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:

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:

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:

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:

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

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.