---
title: "Checking state & counting — Likes for Laravel | Roundly"
description: "Check whether an actor liked a model and count likes with Likes::has() and Likes::for() — live or from an eager-loaded count."
url: https://roundly-consulting.com/open-source/docs/likes-for-laravel/checking-state
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)

# Checking state & counting

Ask the facade whether a like exists, and read one likeable through the Likes::for() handle:

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

Likes::has($post);                        // bool — as the resolved actor
Likes::actor($user)->has($post);          // bool — as any actor
Likes::for($post)->likedBy($user);        // bool — default reaction type unless given
Likes::for($post)->likedBy($user, 'love');

Likes::for($post)->count();               // int — all reactions (uses an eager-loaded likes_count)
Likes::for($post)->count('love');         // int — one type (uses an eager-loaded likes_love_count)
```

## The trait shorthand

The same reads from either model — hasLiked() and isLikedBy() go through Likes::for()->likedBy(), likesCount() through Likes::for()->count():

```php
$post->hasBeenLikedBy($user);  // bool
$post->isLikedBy($user);       // bool — readable alias of hasBeenLikedBy()
$user->hasLiked($post);        // bool

$post->likesCount();           // int — all reactions; uses an eager-loaded likes_count when present
```

Without a type, the checks look for the default reaction. Pass a type to check a specific one:

```php
$post->isLikedBy($user, 'love');
$user->hasLiked($post, 'love');
$post->likesCount('love');     // int — one type; uses an eager-loaded likes_love_count when present
```

## How counting works

- Without a type it counts every active reaction on the model.
- It reuses an eager-loaded likes\_count attribute when present (withLikesCount() or loadCount('likes')), so lists don’t run one query per row.
- With a type it reuses that type’s own eager-loaded attribute — likes\_love\_count from withLikesCount('love') — and otherwise runs a live count for that type. The all-reactions likes\_count never answers a typed count.

```php
$posts = Post::withLikesCount()->withLikesCount('love')->get();  // both attributes on one row

foreach ($posts as $post) {
    Likes::for($post)->count();       // reads likes_count — no extra query (so does $post->likesCount())
    Likes::for($post)->count('love'); // reads likes_love_count
}

$post->loadCount('likes');     // or load the count onto a single model
```

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