balajidharma/laravel-reaction
Composer 安装命令:
composer require balajidharma/laravel-reaction
包简介
Reaction management system for Laravel models
README 文档
README
Reaction management system for Laravel models.
Overview
Laravel Reaction allows you to add reaction to your Laravel models with support for different reaction types.
Table of Contents
Installation
- Install the package via composer
composer require balajidharma/laravel-reaction
- Publish the migration with
php artisan vendor:publish --provider="BalajiDharma\LaravelReaction\ReactionServiceProvider" --tag="migrations"
- Run the migration
php artisan migrate
- To Publish the config/reaction.php config file with
php artisan vendor:publish --provider="BalajiDharma\LaravelReaction\ReactionServiceProvider" --tag="config"
- Preparing your model
To associate reactor with a model, the model must implement the HasReactor trait:
<?php namespace App\Models; use BalajiDharma\LaravelReaction\Traits\HasReactor; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends extends Authenticatable { use HasReactor;
To associate reaction with a model, the model must implement the HasReaction trait:
<?php namespace BalajiDharma\LaravelForum\Models; use BalajiDharma\LaravelReaction\Traits\HasReaction; use Illuminate\Database\Eloquent\Model; class Thread extends Model { use HasReaction;
Add Reaction
use the react method to save the reaction
<?php $thread->react($type, $name, $user = null, $value = null); // React with current user $thread->react('likes', 'like'); $thread->react('likes', 'unlike'); $thread->react('stars', 'star', null, 5); // React by another user $user = User::find(1); $thread->react('likes', 'like', $user);
Remove Reactions
<?php $thread->removeReaction($type, $name = null, $user = null); // Remove reactions by type $thread->removeReaction('likes'); // Remove reactions by type and name $thread->removeReaction('likes', 'like'); $thread->removeReaction('likes', 'unlike'); // Remove reactions by user $user = User::find(1); $thread->react('likes', 'like', $user);
Get Reactions
<?php $thread->getReactions($type, $name = null, $user = null); // Get reactions by type $thread->getReactions('likes'); // Get reactions by type and name $thread->getReactions('likes', 'like'); $thread->getReactions('likes', 'unlike'); // Get reactions by user $user = User::find(1); $thread->getReactions('likes', null, $user); $thread->getReactions('likes', 'like', $user);
Reaction summary
<?php $thread->reactionSummary($type); // example $article->reactionSummary('likes')->toArray(); // output /* [ "like" => 8, "unlike" => -2, ] */
Check if user reacted
<?php // check for current user $thread->isReactBy('likes'); // check for other user $user = User::find(1); $thread->isReactBy('likes', $user);
Demo
The "Basic Laravel Admin Penel" starter kit come with Laravel Reaction
balajidharma/laravel-reaction 适用场景与选型建议
balajidharma/laravel-reaction 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.94k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 12 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「laravel-framework」 「reaction」 「laravel-like」 「laravel-reaction」 「laravel-vote」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 balajidharma/laravel-reaction 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 balajidharma/laravel-reaction 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 balajidharma/laravel-reaction 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Implement reactions (like, dislike, love, emotion etc) on Laravel Eloquent models.
React to something in Laravel framework
A flexible attribute management system for Laravel models
Laravel form builder
Laravel CRUD - Build List and Detail View
Laravel 5 Guzzle wrapper for easy access to API endpoints
统计信息
- 总下载量: 4.94k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 24
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-22