PHPackages                             qirolab/laravel-reactions - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. qirolab/laravel-reactions

ActiveLibrary[Database &amp; ORM](/categories/database)

qirolab/laravel-reactions
=========================

Implement reactions (like, dislike, love, emotion etc) on Laravel Eloquent models.

3.2.2(2mo ago)19670.3k↓11.6%26MITPHPPHP ^8.2CI passing

Since Jul 18Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/qirolab/laravel-reactions)[ Packagist](https://packagist.org/packages/qirolab/laravel-reactions)[ Docs](https://qirolab.com)[ Fund](https://www.buymeacoffee.com/qirolab)[ RSS](/packages/qirolab-laravel-reactions/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (12)Versions (26)Used By (0)

Add Reactions (like, dislike, etc.) to Eloquent Model
=====================================================

[](#add-reactions-like-dislike-etc-to-eloquent-model)

[![](https://camo.githubusercontent.com/d5eb0e39ec756128c932c131b94fba30866783da7f75bec17eb88853e31c7dbe/68747470733a2f2f692e696d6775722e636f6d2f525141707939362e706e67)](https://camo.githubusercontent.com/d5eb0e39ec756128c932c131b94fba30866783da7f75bec17eb88853e31c7dbe/68747470733a2f2f692e696d6775722e636f6d2f525141707939362e706e67)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c0ecefd1292c087395499fd71a3a18d8fbfc4d069dc0152767f8cad314bdbe54/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7169726f6c61622f6c61726176656c2d7265616374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/qirolab/laravel-reactions)[![GitHub Tests Action Status](https://camo.githubusercontent.com/ada7d8d925b9f441ca4f4232756918a76b70c1494edc494d6134d3609745e916/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7169726f6c61622f6c61726176656c2d7265616374696f6e732f54657374733f6c6162656c3d5465737473)](https://github.com/qirolab/laravel-reactions/actions?query=workflow%3ATests+branch%3Amaster)[![Styling](https://github.com/qirolab/laravel-reactions/workflows/Check%20&%20fix%20styling/badge.svg)](https://github.com/qirolab/laravel-reactions/actions?query=workflow%3A%22Check+%26+fix+styling%22)[![Psalm](https://github.com/qirolab/laravel-reactions/workflows/Psalm/badge.svg)](https://github.com/qirolab/laravel-reactions/actions?query=workflow%3APsalm)[![Total Downloads](https://camo.githubusercontent.com/7cb0cc46e0a984daf6dcbb542010f478383e376b5022d971dde520312b6e9875/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7169726f6c61622f6c61726176656c2d7265616374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/qirolab/laravel-reactions)

Laravel reactions package for implementing reactions (eg: like, dislike, love, emotion etc) on Eloquent models.

Video Tutorial
--------------

[](#video-tutorial)

**[ ▶️ Laravel Reactions Tutorial](https://www.youtube.com/watch?v=VMaXBYYDfg8)**

Installation
------------

[](#installation)

Download package into the project using Composer.

```
composer require qirolab/laravel-reactions
```

### Registering package

[](#registering-package)

> Laravel 5.5 (or higher) uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

For Laravel 5.4 or earlier releases version include the service provider within `app/config/app.php`:

```
'providers' => [
    Qirolab\Laravel\Reactions\ReactionsServiceProvider::class,
],
```

### Database Migration

[](#database-migration)

If you want to make changes in migrations, publish them to your application first.

```
php artisan vendor:publish --provider="Qirolab\Laravel\Reactions\ReactionsServiceProvider" --tag=migrations
```

Run database migrations.

```
php artisan migrate
```

### Config File

[](#config-file)

You can optionally publish the config file with:

```
php artisan vendor:publish --provider="Qirolab\Laravel\Reactions\ReactionsServiceProvider" --tag="config"
```

Usage
-----

[](#usage)

### Prepare Reacts (User) Model

[](#prepare-reacts-user-model)

Use `Qirolab\Laravel\Reactions\Contracts\ReactsInterface` contract in model which will perform react behavior on reactable model and implement it and use `Qirolab\Laravel\Reactions\Traits\Reacts` trait.

```
use Qirolab\Laravel\Reactions\Traits\Reacts;
use Qirolab\Laravel\Reactions\Contracts\ReactsInterface;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements ReactsInterface
{
    use Reacts;
}
```

### Prepare Reactable Model

[](#prepare-reactable-model)

Use `Qirolab\Laravel\Reactions\Contracts\ReactableInterface` contract in model which will get reaction behavior and implement it and use `Qirolab\Laravel\Reactions\Traits\Reactable` trait.

```
use Illuminate\Database\Eloquent\Model;
use Qirolab\Laravel\Reactions\Traits\Reactable;
use Qirolab\Laravel\Reactions\Contracts\ReactableInterface;

class Article extends Model implements ReactableInterface
{
    use Reactable;
}
```

Available Methods
-----------------

[](#available-methods)

### Reaction

[](#reaction)

```
$user->reactTo($article, 'like');

$article->react('like'); // current login user
$article->react('like', $user);
```

### Remove Reaction

[](#remove-reaction)

Removing reaction of user from reactable model.

```
$user->removeReactionFrom($article);

$article->removeReaction(); // current login user
$article->removeReaction($user);
```

### Toggle Reaction

[](#toggle-reaction)

The toggle reaction method will add a reaction to the model if the user has not reacted. If a user has already reacted, then it will replace the previous reaction with a new reaction. For example, if the user has reacted 'like' on the model. Now on toggles reaction to 'dislike' then it will remove the 'like' and stores the 'dislike' reaction.

If a user has reacted `like` then on toggle reaction with `like`. It will remove the reaction.

```
$user->toggleReactionOn($article, 'like');

$article->toggleReaction('like'); // current login user
$article->toggleReaction('like', $user);
```

### Boolean check if user reacted on model

[](#boolean-check-if-user-reacted-on-model)

```
$user->isReactedOn($article));

$article->is_reacted; // current login user
$article->isReactBy(); // current login user
$article->isReactBy($user);
```

### Reaction summary on model

[](#reaction-summary-on-model)

```
$article->reactionSummary();
$article->reaction_summary;

// example
$article->reaction_summary->toArray();
// output
/*
[
    "like" => 5,
    "dislike" => 2,
    "clap" => 4,
    "hooray" => 1
]
*/
```

### Get collection of users who reacted on model

[](#get-collection-of-users-who-reacted-on-model)

```
$article->reactionsBy();
```

### Scopes

[](#scopes)

Find all articles reacted by user.

```
Article::whereReactedBy()->get(); // current login user

Article::whereReactedBy($user)->get();
Article::whereReactedBy($user->id)->get();
```

### Reaction on Model

[](#reaction-on-model)

```
// It will return the Reaction object that is reacted by given user.
$article->reacted($user);
$article->reacted(); // current login user
$article->reacted; // current login user

$user->reactedOn($article);
```

### Events

[](#events)

On each reaction added `\Qirolab\Laravel\Reactions\Events\OnReaction` event is fired.

On each reaction removed `\Qirolab\Laravel\Reactions\Events\OnDeleteReaction` event is fired.

### Testing

[](#testing)

Run the tests with:

```
vendor/bin/phpunit
```

[![Spec Coder](https://camo.githubusercontent.com/8bb401f2c52df4de04c96c5450e61946a7fbfd36d407bda0fc77c66dce86716c/68747470733a2f2f692e696d6775722e636f6d2f6c716b743761332e706e67)](https://qirolab.com/spec-coder)

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance86

Actively maintained with recent releases

Popularity49

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 93.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~177 days

Recently: every ~171 days

Total

17

Last Release

67d ago

Major Versions

1.0.0 → 2.0.02018-12-30

2.8.0 → 3.0.02024-06-11

PHP version history (4 changes)1.0.0PHP ^7.0

2.6.0PHP &gt;=7.0

2.7.0PHP &gt;=7.3

3.2.1PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/39181262?v=4)[Harish Kumar](/maintainers/hkp22)[@hkp22](https://github.com/hkp22)

![](https://www.gravatar.com/avatar/4f443ca23815908ed429c01a04b0eb7d1ec7c815967f97b069d87d65210c0040?d=identicon)[qirolab](/maintainers/qirolab)

---

Top Contributors

[![hkp22](https://avatars.githubusercontent.com/u/39181262?v=4)](https://github.com/hkp22 "hkp22 (102 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![Biostate](https://avatars.githubusercontent.com/u/5051330?v=4)](https://github.com/Biostate "Biostate (1 commits)")[![Draesia](https://avatars.githubusercontent.com/u/2690602?v=4)](https://github.com/Draesia "Draesia (1 commits)")[![jeffersongoncalves](https://avatars.githubusercontent.com/u/411493?v=4)](https://github.com/jeffersongoncalves "jeffersongoncalves (1 commits)")[![thijskuilman](https://avatars.githubusercontent.com/u/3017676?v=4)](https://github.com/thijskuilman "thijskuilman (1 commits)")

---

Tags

dislikeeloquentemotionfavoritekudoslaravellikeloverateratingreactionstarunlikelaraveleloquentRatelikefavoritefavouriteRatingstarlovekudosdislikeUnlikeemotionreaction

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/qirolab-laravel-reactions/health.svg)

```
[![Health](https://phpackages.com/badges/qirolab-laravel-reactions/health.svg)](https://phpackages.com/packages/qirolab-laravel-reactions)
```

###  Alternatives

[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k332.0k1](/packages/cybercog-laravel-love)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[watson/validating

Eloquent model validating trait.

9803.5M54](/packages/watson-validating)[rtconner/laravel-likeable

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

400396.7k5](/packages/rtconner-laravel-likeable)[aimeos/laravel-nestedset

Nested Set Model for Laravel

3714.4k6](/packages/aimeos-laravel-nestedset)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
