---
title: "Feed hydration (no N+1) — Likes for Laravel | Roundly"
description: "withLikedState() adds is_liked and liked_reaction for the viewer to a whole feed page in one query — guest-safe."
url: https://roundly-consulting.com/open-source/docs/likes-for-laravel/feed-hydration
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)

# Feed hydration (no N+1)

Render per-row viewer state for an entire feed page in a single query instead of one exists() per row. withLikedState() adds two attributes to each model:

```php
$posts = Post::query()
    ->withLikedState()      // adds is_liked + liked_reaction for the current viewer
    ->withLikesCount()      // composes — still one query
    ->latest()
    ->paginate();
```

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

- is\_liked is a 0/1 flag; liked\_reaction is the viewer’s reaction type or null. When the viewer left several reactions, liked\_reaction is the one listed first in config('likes.reactions').
- The actor defaults to the resolved auth actor (actor\_resolver, else auth()->user()).
- For guests — no resolvable actor — it renders is\_liked = 0 and liked\_reaction = null without throwing, so guest feeds still work.

## Explicit actor & reaction

Pass an actor explicitly, and narrow to one reaction type:

```php
Post::withLikedState($user)->get();           // an explicit actor
Post::withLikedState($user, 'love')->get();   // only the viewer's "love" counts as liked
```

Both attributes come from correlated subqueries on the likes table, so the scope composes with withLikesCount(), eager loads, pagination and your own select() calls.

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