PHP code example of phunky / laravel-messaging-reactions

1. Go to this page and download the library: Download phunky/laravel-messaging-reactions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phunky / laravel-messaging-reactions example snippets


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

use Phunky\LaravelMessagingReactions\ReactionService;

$reactionService = app(ReactionService::class);

// 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, '❤️');

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

// 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->reactions()->get();
$message->reactions()->count();

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));
});
bash
php artisan migrate