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

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

mohammadrasoulasghari/laravel-reactions
=======================================

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

v1.0.0(11mo ago)0488MITPHPPHP &gt;=7.3

Since May 25Pushed 11mo agoCompare

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

READMEChangelog (1)Dependencies (6)Versions (2)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
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance50

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor1

Top contributor holds 91.8% 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

Unknown

Total

1

Last Release

353d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c75955a0ef98a57ab6df284f547ed29656be9692b31b2ca5161ef1aa31db3316?d=identicon)[mohammadrasoulasghari](/maintainers/mohammadrasoulasghari)

---

Top Contributors

[![hkp22](https://avatars.githubusercontent.com/u/39181262?v=4)](https://github.com/hkp22 "hkp22 (90 commits)")[![rezaghz](https://avatars.githubusercontent.com/u/36597017?v=4)](https://github.com/rezaghz "rezaghz (2 commits)")[![jeffersongoncalves](https://avatars.githubusercontent.com/u/411493?v=4)](https://github.com/jeffersongoncalves "jeffersongoncalves (1 commits)")[![mohammadgh1370](https://avatars.githubusercontent.com/u/38649905?v=4)](https://github.com/mohammadgh1370 "mohammadgh1370 (1 commits)")[![mohammadrasoulasghari](https://avatars.githubusercontent.com/u/112411294?v=4)](https://github.com/mohammadrasoulasghari "mohammadrasoulasghari (1 commits)")[![Biostate](https://avatars.githubusercontent.com/u/5051330?v=4)](https://github.com/Biostate "Biostate (1 commits)")[![thijskuilman](https://avatars.githubusercontent.com/u/3017676?v=4)](https://github.com/thijskuilman "thijskuilman (1 commits)")[![Draesia](https://avatars.githubusercontent.com/u/2690602?v=4)](https://github.com/Draesia "Draesia (1 commits)")

---

Tags

laraveleloquentRatelikefavoritefavouriteRatingstarlovekudosdislikeUnlikeemotionreaction

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/mohammadrasoulasghari-laravel-reactions/health.svg)](https://phpackages.com/packages/mohammadrasoulasghari-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)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[rennokki/rating

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

19016.9k](/packages/rennokki-rating)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)

PHPackages © 2026

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