cybercog/laravel-love
Add reactions, likes, votes, and other “feelings” to any Eloquent model with Laravel Love. Flexible, enterprise-ready system inspired by GitHub/Facebook/Slack reactions. Includes migrations and APIs to make models reactable in minutes.
ReactionType contracts. Supports both binary (like/dislike) and multi-value systems.ReactionTotal and ReactionCounter models, reducing query load.use \Cog\Laravel\Love\Traits\Reacterable;).love_reactions (user-reaction-content links + weights).love_reaction_types (customizable reaction labels).love_reactant_reaction_totals (aggregated counts).Post, Comment, Product). Supports polymorphic relationships if needed.reactTo($reactant, $type, $rate) (create/update reactions).hasReactedTo($reactant, $type) (check reactions).reactions() (fetch user reactions).| Risk Area | Assessment | Mitigation |
|---|---|---|
| Migration Complexity | Breaking changes in v8/v9 (e.g., weighted system, schema shifts). Upgrade path requires love:upgrade-v7-to-v8 Artisan command. |
Test upgrade in staging; use UPGRADING.md as a checklist. |
| Performance at Scale | Aggregation jobs (IncrementReactionAggregatesJob) run asynchronously but may lag under high write loads. |
Monitor queue backlogs; consider batching or caching aggregates (e.g., Redis). |
| Customization Overhead | Advanced features (e.g., custom weights, reaction types) require config tweaks or model overrides. | Document customization in a ReactionConfig service class. |
| Legacy Compatibility | Dropped support for Laravel <9/PHP <8.0. If using older versions, fork or use v7.x. | Audit dependencies; plan for upgrade if on unsupported stack. |
| Testing Gaps | Limited test coverage for edge cases (e.g., concurrent reactions, rate limits). | Add integration tests for critical paths (e.g., Reacter::reactTo race conditions). |
Reaction Granularity:
ReactionType::setWeight()).ReactionType::create(['name' => 'love', 'weight' => 1])->save();Aggregation Strategy:
ReactionTotal counters, or implement custom caching (e.g., Redis) for performance?User Identity:
Auth::id(), but supports custom Reacter models (e.g., TeamMember).User::find(1)->reactTo($post, 'love');Rate Limits:
throttle).Frontend Integration:
{{ $post->reactions()->count() }} likes.Analytics:
Multi-Tenancy:
reactant_id/reacter_id are scoped per tenant.| Step | Action | Tools/Commands |
|---|---|---|
| Prerequisite Check | Verify Laravel/PHP compatibility. If on v<9, fork or use v7.x. | composer show laravel/framework |
| Installation | Add package and run migrations. | composer require cybercog/laravel-love php artisan migrate |
| Model Setup | Mark models as "reactable" (e.g., Post). |
php artisan make:model Post --reactable Or manually: use Reacterable; |
| Reaction Types | Define custom reaction types (e.g., "love," "haha"). | ReactionType::create(['name' => 'love'])->save(); |
| Configuration | Tweak weights, defaults, or table names in config/love.php. |
config/love.php |
| Upgrade (if needed) | Run upgrade command for major versions (e.g., v7→v8). | php artisan love:upgrade-v7-to-v8 |
| Testing | Validate reactions, aggregates, and edge cases. | php artisan test Or Docker: docker compose exec php85 composer test |
Reacterable trait.Activitylog).Observers don’t interfere with ReactionObserver.POST /reactions) align with frontend calls.Phase 1: Core Integration
Post, Comment) as reactable.Phase 2: Customization
love = +1, dislike = -1).Phase 3: Aggregation & Performance
Phase 4: Analytics/Reporting
Phase 5: Scaling
RebuildReactionAggregatesJob.How can I help you explore Laravel packages today?