---
title: "Likes & reactions — Posts for Laravel | Roundly"
description: "Like, unlike and toggle posts, rank popular and trending feeds, and hydrate each viewer’s state in a single query."
url: https://roundly-consulting.com/open-source/docs/posts-for-laravel/likes
language: en
---

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

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

# Likes & reactions

The bundled Post implements Likeable through the HasPostReactions concern, built on likes-for-laravel. The actor is always passed explicitly — posts never reads the acting user from the auth guard:

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

Likes::actor($user)->like($post);     // like / unlike / toggle
Likes::actor($user)->toggle($post);   // returns the resulting is-liked state
Likes::actor($user)->unlike($post);

$post->isLikedBy($user);              // bool
$post->likesCount();                  // int (uses an eager count when hydrated)
```

## Popular and trending feeds

Ranking and per-viewer hydration compose as scopes:

```php
Post::published()->orderByLikesDesc()->limit(10)->get();   // "popular"
Post::published()->orderByTrending()->get();               // recency-weighted

$feed = Post::published()
    ->withLikesCount()              // hydrate likes_count
    ->withLikedState($viewer)       // hydrate is_liked + liked_reaction (pass the viewer)
    ->latest()
    ->paginate();
```

```blade
@foreach ($feed as $post)
    {{ $post->is_liked ? '♥' : '♡' }} {{ $post->likes_count }}
@endforeach
```

orderByLikes(), orderByLikeScore(), whereLikedBy() and whereNotLikedBy() are available too, as are the likes() relation, hasBeenLikedBy(), reactionSummary() and toLikeArray().

## Compact payload

For an API or Blade, likeState() returns the count, the viewer’s state and the per-reaction breakdown:

```php
$post->likeState($viewer);
// => ['count' => 12, 'viewer_state' => ['liked' => true, 'reaction' => 'like'], 'breakdown' => ['like' => 12]]
```

A null viewer renders a guest state (liked false, reaction null). Typed reactions such as love or wow come from the host’s likes.reactions config — see the likes-for-laravel docs.

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