phunky/laravel-messaging-reactions 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phunky/laravel-messaging-reactions

最新稳定版本:0.1.1

Composer 安装命令:

composer require phunky/laravel-messaging-reactions

包简介

Message reactions extension for phunky/laravel-messaging

README 文档

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.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固