phunky/laravel-messaging-reactions

Message reactions extension for phunky/laravel-messaging

Maintainers

Package info

github.com/Phunky/laravel-messaging-reactions

Homepage

Issues

pkg:composer/phunky/laravel-messaging-reactions

Statistics

Installs: 0

Dependents: 0

Suggesters: 1

Stars: 0

0.0.1 2026-04-16 15:17 UTC

This package is auto-updated.

Last update: 2026-04-16 15:48:18 UTC


README

Per-message reactions for phunky/laravel-messaging. Each conversation participant can add one reaction per message. Values are plain strings โ€” emoji, icon slugs (e.g. for Flux <flux:icon>), or any convention your UI uses.

Installation

composer require phunky/laravel-messaging-reactions

Register the extension in config/messaging.php (add to the existing extensions array โ€” do not remove the core keys):

'extensions' => [
    // ... other MessagingExtension classes, if any
    \Phunky\LaravelMessagingReactions\ReactionsExtension::class,
],
php artisan migrate

Usage

Resolve ReactionService via the container (constructor injection, app(ReactionService::class), etc.):

use Phunky\LaravelMessagingReactions\ReactionService;

$reactionService = app(ReactionService::class);

Reacting to a message

// Add or change a reaction โ€” returns the Reaction model
$reaction = $reactionService->react($message, $user, '๐Ÿ‘');

// Same value again removes the reaction (toggle) โ€” returns null
$reaction = $reactionService->react($message, $user, '๐Ÿ‘');

// A different value replaces the existing reaction
$reaction = $reactionService->react($message, $user, 'โค๏ธ');

Each participant has at most one reaction per message (one row per participant, updated in place). Only conversation participants may react โ€” others throw an exception.

Removing a reaction

// Removes the participantโ€™s current reaction if any; no-op if none
$reactionService->removeReaction($message, $user);

Fetching reactions

// Reaction models with participant and messageable eager-loaded
$reactions = $reactionService->getReactions($message);

// Grouped summary for counts in the UI
$summary = $reactionService->getReactionSummary($message);

// Each item: ['reaction' => '๐Ÿ‘', 'count' => 3, 'participant_ids' => [1, 4, 7]]

Message relationship

Message::reactions() is registered as a hasMany macro โ€” call it as a method:

$message->reactions()->get();
$message->reactions()->count();

Events

ReactionAdded and ReactionRemoved extend [BroadcastableMessagingEvent](https://github.com/phunky/laravel-messaging) from the core package. They implement ShouldBroadcast and ShouldDispatchAfterCommit, respect config('messaging.broadcasting.enabled'), and use the same private conversation channels as core messaging. With Laravel Echo, listen using the broadcastAs() name with a leading dot (e.g. .listen('.messaging.reaction.added', โ€ฆ)).

Event Public properties broadcastAs()
ReactionAdded $reaction, $message, $messageable messaging.reaction.added
ReactionRemoved $message, $messageable, $reaction (string) messaging.reaction.removed

ReactionAdded includes the full Reaction model (participant is loaded before dispatch). ReactionRemoved passes the reaction string because the row is already gone.

use Illuminate\Support\Facades\Event;
use Phunky\LaravelMessagingReactions\Events\ReactionAdded;

Event::listen(ReactionAdded::class, function (ReactionAdded $event) {
    $event->message->sender?->notify(new \App\Notifications\MessageReacted($event->reaction));
});

License

MIT - see LICENSE.md.