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

Fund package maintenance!

2.6.0 2022-02-11 09:24 UTC

This package is auto-updated.

Last update: 2022-05-11 09:56:27 UTC



Latest Version on Packagist GitHub Tests Action Status Styling Psalm Total Downloads

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

Video Tutorial

▶️ Laravel Reactions Tutorial


Download package into the project using Composer.

$ composer require qirolab/laravel-reactions

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' => [

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


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

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


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

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

Remove Reaction

Removing reaction of user from reactable model.


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

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


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

Reaction summary on model


// example
// output
    "like" => 5,
    "dislike" => 2,
    "clap" => 4,
    "hooray" => 1

Get collection of users who reacted on model



Find all articles reacted by user.

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


Reaction on Model

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



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

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


Run the tests with:

$ vendor/bin/phpunit