---
title: "Likes & ranking — Comments for Laravel | Roundly"
description: "Like, upvote and react to comments via Likes for Laravel, then rank threads by most-liked or trending with per-viewer state in one query."
url: https://roundly-consulting.com/open-source/docs/comments-for-laravel/likes
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Comments for Laravel](https://roundly-consulting.com/open-source/docs/comments-for-laravel.md)

# Likes & ranking

Comment reactions are powered by Likes for Laravel: the Comment model implements Likeable, so any model can like or upvote it. Actors are always passed explicitly — the package never resolves the acting user from the auth guard:

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

Likes::actor($user)->like($comment);
Likes::actor($user)->unlike($comment);
Likes::actor($user)->toggle($comment);   // bool: now liked?

$comment->likesCount();        // live or eager count
$comment->isLikedBy($user);    // bool
$comment->likeState($viewer);  // ['count' => 2, 'viewer_state' => ['liked' => true, 'reaction' => 'like'], 'breakdown' => ['like' => 2]]
```

## Typed reactions

Beyond a plain like, react() keeps one active reaction per actor and switches it in place. Reaction types must be listed in the likes.reactions allowlist:

```php
// config/likes.php → 'reactions' => ['like', 'love'],
Likes::actor($user)->as('love')->react($comment); // one active reaction, switched in place

$comment->likesCount('love');        // count for one reaction type
$comment->isLikedBy($user, 'love');  // bool
```

## Ranking & viewer state

Rank and hydrate a whole thread through the CommentQuery builder — most-liked, trending, and single-query per-viewer like-state (no N+1):

```php
Comments::for($post)->orderByLikesDesc()->get();      // "top comments"
Comments::for($post)->orderByTrending()->get();       // recency-weighted "hot"
Comments::for($post)->withLikedState($viewer)->get(); // each row: ->is_liked, ->liked_reaction
```

likeState() returns a compact payload for APIs and Blade — the total count, the viewer’s state and the per-reaction breakdown. Pass the viewer explicitly; without one it renders a guest state.

## 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/comments-for-laravel.md)
