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

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

francescomalatesta/laravel-reactions
====================================

0.1.1(9y ago)58160MITPHP ~5.6|~7.0

Since Mar 26Compare

[ Source](https://github.com/francescomalatesta/laravel-reactions)[ Packagist](https://packagist.org/packages/francescomalatesta/laravel-reactions)[ Docs](https://github.com/francescomalatesta/laravel-reactions)[ RSS](/packages/francescomalatesta-laravel-reactions/feed)WikiDiscussions Synced 2w ago

READMEChangelogDependencies (6)Versions (3)Used By (0)

Laravel Reactions
=================

[](#laravel-reactions)

[![Latest Version on Packagist](https://camo.githubusercontent.com/83367f82374e6defb22a592e337fb3f86be54829514f1b3a2d0361884210937c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6672616e636573636f6d616c6174657374612f6c61726176656c2d7265616374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/francescomalatesta/laravel-reactions)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/d7b74bda1361f4c48140f92d46aa00b2f2acb02cde9a84aeeefe32cdfc70ac60/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6672616e636573636f6d616c6174657374612f6c61726176656c2d7265616374696f6e732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/francescomalatesta/laravel-reactions)[![Quality Score](https://camo.githubusercontent.com/51be0927756e3b8511e4ddc4f1f8ba59f60ba1a14c6493ad16fe1791a5911337/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6672616e636573636f6d616c6174657374612f6c61726176656c2d7265616374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/francescomalatesta/laravel-reactions)[![Total Downloads](https://camo.githubusercontent.com/45cab0607a0280c944ab2c24ad7e6d5ca2f72b0f00f86d7170cc0af6a00d6d05/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6672616e636573636f6d616c6174657374612f6c61726176656c2d7265616374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/francescomalatesta/laravel-reactions)

Laravel Reactions is the package you need if you want to implement reactions for your Eloquent models, in a similar way you can see on Facebook.

#### Features

[](#features)

- easy to install, nothing to configure;
- ready-to-use traits;
- you can implement reactions for multiple entities, thanks to a polymorphic many to many relationship;
- you can implement reactions from multiple entities, thanks to some extra magic under the hood;

#### Disclaimer

[](#disclaimer)

**This project is not associated with Facebook in any way.** I've used the "reactions" just to give an idea of the concept. In case of legal issues, let me know using an email.

Install
-------

[](#install)

Install the package with Composer.

```
$ composer require francescomalatesta/laravel-reactions
```

Add the Service Provider to your `config/app.php` file.

```
FrancescoMalatesta\LaravelReactions\Providers\ReactionsServiceProvider::class,
```

Run the migrations to create `reactions` and `reactables` tables.

```
$ php artisan migrate
```

You're good to go.

Usage
-----

[](#usage)

### Add Traits to Models

[](#add-traits-to-models)

To use the package you need to follow two steps:

- add the `FrancescoMalatesta\LaravelReactions\Traits\Reacts` trait to the entity that is going to react to something;
- add the `FrancescoMalatesta\LaravelReactions\Traits\Reactable` trait to the entity that is going to "receive" reactions;
- be sure that the entity that receives reactions also implements the `FrancescoMalatesta\LaravelReactions\Contracts\ReactableInterface`;

Let's make an example.

Imagine that you have some users in your application. You are building a blog, so you will have posts.

You want to let your user add reactions to your posts. Just like Facebook, you know.

Let's say we have two models: `User` and `Post`.

Following the steps, we first add the `FrancescoMalatesta\LaravelReactions\Traits\Reacts` trait to our `User` model.

```
use FrancescoMalatesta\LaravelReactions\Traits\Reacts;

class User extends Model {
    use Reacts;
}
```

Done! Now, to the `Post` model!

```
use FrancescoMalatesta\LaravelReactions\Traits\Reacts;
use FrancescoMalatesta\LaravelReactions\Contracts\ReactableInterface;

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

Ta-dah! You're done.

By default, the package ships with a `Reaction` model. This model has a single, simple property: its `name`. You can create a new one easily, with

```
$likeReaction = Reaction::createFromName('like');
$likeReaction->save();

$loveReaction = Reaction::createFromName('love');
$loveReaction->save();
```

### React!

[](#react)

Our models are ready. We can use them. How?

```
// picking the first user, for this example...
$user = User::first();

// the previously created reaction
$likeReaction = Reaction::where('name', '=', 'like')->first();

// picking up a post...
$awesomePost = Post::first();

// react to it!
$user->reactTo($awesomePost, $likeReaction);
```

Easy, isn't it? The `reactTo` method handles everything for you.

### Get Reactions for a Model

[](#get-reactions-for-a-model)

Just like you can let one of your entities react to another one, you should be able to get all the reactions for an entity.

Let's see how to do it.

```
// picking up a post...
$awesomePost = Post::first();

// get all reactions
$reactions = $awesomePost->reactions;
```

In `$reactions` you will have a collection of `Reaction` models, ready to be used.

### Get a Reactions Summary

[](#get-a-reactions-summary)

Probably you won't need everything about reactions to a specific entity everytime. So, I implemented a `getReactionsSummary` for you.

```
// picking up a post...
$awesomePost = Post::first();

// get a summary of related reactions
$reactionsSummary = $awesomePost->getReactionsSummary();
```

In `$reactionsSummary` you will find a collection of items, composed by two properties: `name` and `count`. Imagine that we do something like the following code in a controller:

```
$reactionsSummary = $awesomePost->getReactionsSummary();
return $reactionsSummary;
```

Here's what we will get:

```
[
    {
        "name": "like",
        "count": 12
    },
    {
        "name": "love",
        "count": 7
    }
]
```

### Accessing the "Responder"

[](#accessing-the-responder)

When on Facebook, you can see "who" reacted in some way to a post. To get that `who` you can use the `getResponder` method. This works for every reaction you get using the `reactions` relationship method, of course.

Let's assume that a `User` named "Francesco" already reacted with the "love" reaction to a post.

```
// our awesome post.
$awesomePost = Post::first();

// every $reaction is a Reaction model
foreach($awesomePost->reactions as $reaction)
{
    $user = $reaction->getResponder();

    // this will output "Francesco"
    echo $user->name;
}
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Francesco Malatesta](https://github.com/francescomalatesta)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 46% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

3428d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1940952?v=4)[Francesco Malatesta](/maintainers/francescomalatesta)[@francescomalatesta](https://github.com/francescomalatesta)

---

Top Contributors

[![francescomalatesta](https://avatars.githubusercontent.com/u/1940952?v=4)](https://github.com/francescomalatesta "francescomalatesta (18 commits)")

---

Tags

laravelpackageeloquenttraitlikelovereactions

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.9M109](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k35.7M51](/packages/kirschbaum-development-eloquent-power-joins)[cybercog/laravel-love

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

1.2k341.5k1](/packages/cybercog-laravel-love)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.3M27](/packages/yajra-laravel-oci8)[devdojo/laravel-reactions

3631.4k](/packages/devdojo-laravel-reactions)

PHPackages © 2026

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