1. Go to this page and download the library: Download broqit/laravel-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/ */
broqit / laravel-reactions example snippets
return [
'types' => [
['type' => 'like', 'name' => 'Like', 'icon' => '👍'],
['type' => 'love', 'name' => 'Love', 'icon' => '❤️'],
['type' => 'haha', 'name' => 'Haha', 'icon' => '😂'],
['type' => 'wow', 'name' => 'Wow', 'icon' => '😮'],
['type' => 'sad', 'name' => 'Sad', 'icon' => '😢'],
['type' => 'angry', 'name' => 'Angry', 'icon' => '😡'],
],
'allowed_users' => ['user', 'guest'], // Possible values: 'user', 'guest', 'both'
'max_reactions_per_user' => 1,
'table_name' => 'custom_reactions', // Table name
'user_model' => null, // Default user model - null
'removal_window_hours' => null, // Number of hours within which reactions can be removed, null means no limit
];
use Broqit\Reactions\Traits\HasReactions;
class Post extends Model
{
use HasReactions;
// Your model code
}
// Get the total count of reactions for a post
$totalReactions = $post->getTotalReactionsCount();
// Get the number of 'like' reactions for a post
$likeReactions = $post->getReactionsCountByType('like');
// Get the count of all reactions for a post, grouped by type
$groupedReactions = $post->getReactionsCountGroupedByType();