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.
Reacter, Reactant), enabling flexible integration without tight coupling. Supports weighted reactions (e.g., 1–5 stars) and aggregates (counts/totals).php artisan migrate).Reacterable, Reactantable) on models.love:setup-reactable/love:setup-reacterable (auto-generates migrations).love:recount (rebuilds aggregates asynchronously).ReactionCreated, ReactionDeleted).| Risk Area | Assessment | Mitigation |
|---|---|---|
| Breaking Changes | Major versions (e.g., v8–v9) introduce schema changes (e.g., weighted reactions). | Follow UPGRADING.md and use love:upgrade-v7-to-v8 Artisan command. Test in staging before production. |
| Performance | Aggregates (counts/totals) are denormalized via jobs. High-volume apps may need optimized queries or caching (e.g., Redis for reaction counts). | Monitor love:recount job queues. Use database indexes on reactant_id/reacter_id/reaction_type. Consider read replicas for analytics. |
| Concurrency | Race conditions possible when multiple reactions are created/deleted simultaneously. | Use database transactions for critical operations. Leverage Laravel’s queue workers to process reactions asynchronously. |
| Legacy Support | Dropped support for Laravel <9 and PHP <8.0. | Ensure your stack meets requirements. Use Laravel Shift or Bridges for older versions if needed. |
| Testing Overhead | Complex interactions (e.g., aggregates, events) may require mocking in tests. | Use package’s test utilities (e.g., ReactionFactory). Isolate tests for Reacter/Reactant logic. |
Reaction Granularity:
rate column).Aggregate Strategy:
Scalability Needs:
Custom Validation:
Reacter contract or use model observers.UI/UX Requirements:
| Step | Action | Tools/Commands |
|---|---|---|
| 1. Pre-Integration | Audit Laravel version (9–13) and PHP (8.0–8.5). | php -v, laravel --version |
| 2. Install | Add package via Composer. | composer require cybercog/laravel-love |
| 3. Configure | Publish config (optional): php artisan vendor:publish --provider="Cog\Laravel\Love\LoveServiceProvider". |
config/love.php (custom table names, reaction types) |
| 4. Migrate | Run migrations to create love_reactions, love_reaction_totals, etc. |
php artisan migrate |
| 5. Model Setup | Apply traits to models: | |
- Reactable (content being reacted to, e.g., Post, Comment). |
use Cog\Laravel\Love\Reactant\Traits\Reactantable; |
|
- Reacter (user reacting, e.g., User). |
use Cog\Laravel\Love\Reacter\Traits\Reacterable; |
|
| 6. Customization | Extend contracts or create custom reaction types. | php artisan make:reaction-type Like |
| 7. Testing | Test core functionality: | |
| - Reaction creation/deletion. | Reacter::reactTo(Reactant, 'like') |
|
| - Aggregate counts. | $post->reactionTotals |
|
| - Edge cases (duplicate reactions, rate limits). | ||
| 8. Deployment | Monitor queue jobs (love:recount) and database performance. |
php artisan queue:work |
LoveServiceProvider runs last.POST /posts/{id}/react?type=like; backend processes via Reacter::reactTo().Auth::user()). For custom auth, override reacter() method in Reacterable trait.Post, Comment).reactionTotals) and scopes (whereReactedTo).love:recount job frequency (e.g., cron every 5 mins).love_reactions table by reactant_id for sharding.How can I help you explore Laravel packages today?