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

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

kesty/laravel-reactions
=======================

v1.0.0(3y ago)081MITPHPPHP ^8.0

Since Jul 30Pushed 3y ago1 watchersCompare

[ Source](https://github.com/olubunmitosin/laravel-reactions)[ Packagist](https://packagist.org/packages/kesty/laravel-reactions)[ Docs](https://github.com/olubunmitosin/laravel-reactions)[ RSS](/packages/kesty-laravel-reactions/feed)WikiDiscussions master Synced 3d ago

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

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

[](#laravel-reactions)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6234f1dead632eccaa4921d5546f9ed9dc39fc939148eb65bdb7b1ab626f29b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b657374792f6c61726176656c2d7265616374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kesty/laravel-reactions)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/a6850687224c4e9b80c310f27a8877b27a1d1981b5fd1a84f2468969e0e95fdb/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6b657374792f6c61726176656c2d7265616374696f6e732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/kesty/laravel-reactions)[![Total Downloads](https://camo.githubusercontent.com/6d5cac218de9db1a8d5c0afab2e3ed7fb811a0dc5fd81b64daf2787e6b7d6019/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b657374792f6c61726176656c2d7265616374696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kesty/laravel-reactions)

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

[![](https://camo.githubusercontent.com/81c16eb8ddf61919cec24bb8c706e6610123927e76d1b2f60cbe7e3f66be689e/68747470733a2f2f63646e2e4b657374792e636f6d2f6f70656e2d736f757263652f7265616374696f6e732e6a7067)](https://camo.githubusercontent.com/81c16eb8ddf61919cec24bb8c706e6610123927e76d1b2f60cbe7e3f66be689e/68747470733a2f2f63646e2e4b657374792e636f6d2f6f70656e2d736f757263652f7265616374696f6e732e6a7067)

#### 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 kesty/laravel-reactions
```

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

```
Kesty\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 `Kesty\LaravelReactions\Traits\Reacts` trait to the entity that is going to react to something;
- add the `Kesty\LaravelReactions\Traits\Reactable` trait to the entity that is going to "receive" reactions;
- be sure that the entity that receives reactions also implements the `Kesty\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 `Kesty\LaravelReactions\Traits\Reacts` trait to our `User` model.

```
use Kesty\LaravelReactions\Traits\Reacts;

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

Done! Now, to the `Post` model!

```
use Kesty\LaravelReactions\Traits\Reactable;
use Kesty\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)

- [Olubunmi Tosin](https://github.com/olubunmitosin)
- [All Contributors](../contributors)

License
-------

[](#license)

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

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

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

1382d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7978a46601b22c02edd1e108652d0c4d81943d18a5769e9d97564d23294ca0ee?d=identicon)[olubunmi708](/maintainers/olubunmi708)

---

Tags

laravelpackageeloquenttraitlikelovereactions

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

3529.7k](/packages/devdojo-laravel-reactions)[cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

1.1k651.8k11](/packages/cybercog-laravel-ban)[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)[qirolab/laravel-reactions

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

19564.6k](/packages/qirolab-laravel-reactions)[cybercog/laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.

9126.6k3](/packages/cybercog-laravel-ownership)

PHPackages © 2026

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