Search by

pharaonic / laravel-reacts

Pharaonic

Polymorphic emoji reactions for Laravel Eloquent models, with registered types, grouped catalogs, single or multiple mode, and database-enforced uniqueness.

Package info

github.com/Pharaonic/laravel-reacts

Documentation

pkg:composer/pharaonic/laravel-reacts

Fund package maintenance!

MoamenEltouny

Buy Me A Coffee

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0


README

PHP Version : 8.3 | 8.4 | 8.5 Laravel Version : 13.x License Build
Source Packagist Version Packagist Downloads

Reactions for Eloquent models: configured types, free-form emoji, single or multiple mode.


Installation

composer require pharaonic/laravel-reacts
php artisan migrate

The service provider is registered automatically, and migrate creates the reactions table. Publish the configuration to define your own reaction types and groups:

php artisan vendor:publish --tag=reacts-config

Usage

Add CanReact to the model that reacts and HasReactions to the model that receives reactions:

use Illuminate\Foundation\Auth\User as Authenticatable;
use Pharaonic\Laravel\Reacts\Concerns\CanReact;

class User extends Authenticatable
{
    use CanReact;
}
use Illuminate\Database\Eloquent\Model;
use Pharaonic\Laravel\Reacts\Concerns\HasReactions;

class Post extends Model
{
    use HasReactions;
}
use Pharaonic\Laravel\Reacts\Support\ReactionView;

$user->react($post, 'like');            // true: added
$user->react($post, 'love');            // true: a second type (multiple mode, the default)
$user->react($post, 'love');            // false: already there
$user->toggleReaction($post, 'like');   // false: removed
$user->hasReacted($post, 'love');       // true
$user->react($chatMessage, '🚀');        // true: in a group that allows free-form emoji

$post->reactionCounts();                // ['love' => 1]
ReactionView::for($post, $user)->toArray(); // choices, counts and the viewer's selection, for Blade or JSON

Documentation

Full documentation: Laravel Reacts Documentation.

Support & Security

See SUPPORT.md and SECURITY.md. Contributions are welcome; see CONTRIBUTING.md.

License

MIT. See LICENSE.