PHPackages                             hkp22/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. hkp22/laravel-reactions

Abandoned → [qirolab/laravel-reactions](/?search=qirolab%2Flaravel-reactions)Library[Database &amp; ORM](/categories/database)

hkp22/laravel-reactions
=======================

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

2.5.0(5y ago)1961.5k25MITPHPPHP ^7.0CI passing

Since Jul 18Pushed 2w ago2 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (9)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

47

—

FairBetter than 94% of packages

Maintenance63

Regular maintenance activity

Popularity33

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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 ~130 days

Total

7

Last Release

2072d ago

Major Versions

1.0.0 → 2.0.02018-12-30

### Community

Maintainers

![](https://www.gravatar.com/avatar/409368752f65ba14c0c6bfaabf70353b13096503e1de1e13d3e6aa3899cb13aa?d=identicon)[hkp22](/maintainers/hkp22)

---

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

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[cybercog/laravel-love

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

1.2k302.7k1](/packages/cybercog-laravel-love)[qirolab/laravel-reactions

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

19564.6k](/packages/qirolab-laravel-reactions)[rtconner/laravel-likeable

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

394388.0k5](/packages/rtconner-laravel-likeable)[rennokki/rating

Laravel Eloquent Rating allows you to assign ratings to any model.

19016.9k](/packages/rennokki-rating)[binafy/laravel-reactions

React to something in Laravel framework

874.5k](/packages/binafy-laravel-reactions)

PHPackages © 2026

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