All packages
Likes for Laravel
Reaction breakdown
Likes::for($post)->summary() — or $post->reactionSummary() on the model — returns a ReactionSummary for reaction bars and counters: one grouped count query plus, at most, one lookup for the viewer’s reaction:
$summary = Likes::for($post)->summary($viewer); // viewer optional; same as $post->reactionSummary()
$summary->total; // int — sum of all reactions
$summary->counts; // ['like' => 8, 'love' => 4]
$summary->countFor('love'); // int
$summary->has('love'); // bool
$summary->top; // ?string — most-used type (config order breaks ties), null if none
$summary->viewerReaction; // ?string — the viewer's active reaction (the first configured one if several), null without one
$summary->toArray(); // ['total' => .., 'counts' => [...], 'top' => .., 'viewer' => ..]- counts maps each reaction type to its count; countFor() returns 0 for a type nobody used.
- top is the most-used type; ties go to the type listed first in reactions. viewerReaction is the viewer’s active reaction — the first configured one if they left several.
- Pass a viewer, or let it default to the resolved actor. For guests viewerReaction is null — it never throws.
A reaction bar in Blade
@php($summary = $post->reactionSummary())
@foreach ($summary->counts as $type => $count)
<span @class(['font-semibold' => $summary->viewerReaction === $type])>
{{ $type }} {{ $count }}
</span>
@endforeachShow 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 cryptoBy 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.