- How do I add reactions (like GitHub or Reddit) to a Laravel Eloquent model?
- Use the `Reacterable` trait on your model and run `php artisan migrate` to set up the database tables. Then call `$post->reactTo($user, 'love')` to register a reaction. The package auto-generates the necessary migrations and relationships.
- Can I use custom reaction types like 'laugh,' 'confused,' or 'heart' instead of just 'like/dislike'?
- Yes. Define custom reaction types via the `ReactionType` model or use the `createReactionType` helper. For example, `ReactionType::create(['name' => 'laugh', 'weight' => 1])->save()`. These can be used just like built-in types.
- Does Laravel Love support weighted reactions (e.g., 1-5 stars or sentiment scores)?
- Absolutely. Assign weights to reaction types (e.g., `thumbs-up` = +1, `meh` = 0, `thumbs-down` = -1) via the `weight` field in `ReactionType`. Use `reactTo($model, 'type', $weight)` to apply custom values, like `$post->reactTo($user, 'love', 3)`.
- How do I check if a user has already reacted to a model (e.g., to prevent duplicate likes)?
- Use the `hasReactedTo` method: `$user->hasReactedTo($post, 'love')`. This checks the database for existing reactions between the user and the model. You can also fetch all reactions for a user with `$user->reactions()`.
- Is Laravel Love compatible with Laravel 13 and PHP 8.5? What about older versions?
- The package officially supports Laravel 9–13 and PHP 8.0–8.5. If you're on Laravel <9 or PHP <8.0, use version 7.x of the package. Check the [UPGRADING.md](https://github.com/cybercog/laravel-love/blob/master/UPGRADING.md) guide for migration steps.
- How are reaction counts (e.g., '1.2K reactions') aggregated and updated in real-time?
- Aggregates are updated asynchronously via the `IncrementReactionAggregatesJob`. For high-traffic apps, monitor queue backlogs. You can also cache counts in Redis or implement custom logic for real-time updates using the `ReactionTotal` model.
- Can I use Laravel Love for multi-tenancy (e.g., Laravel Nova or Breeze)?
- Yes, but ensure `reactant_id` (the model being reacted to) and `reacter_id` (the user reacting) are scoped per tenant. If using a custom user model, extend the `Reacter` trait and override the `getAuthId` method to return the correct tenant-aware ID.
- Does this package include frontend UI components for displaying reactions?
- No, Laravel Love focuses on backend logic. You’ll need to build your own UI (e.g., buttons, counters) using Blade or a frontend framework. Example: `{{ $post->reactions()->count() }} likes`. The package provides APIs like `reactions()` to fetch data for your UI.
- How do I rate-limit reactions (e.g., 1 reaction per minute per user)?
- Laravel Love doesn’t include rate-limiting by default. Use Laravel’s `throttle` middleware or packages like `spatie/rate-limiter` to restrict reactions. Example: Apply middleware to your reaction endpoint to limit calls based on `reacter_id`.
- Are there alternatives to Laravel Love for simpler like/dislike systems?
- For basic likes/dislikes, consider `spatie/laravel-activitylog` (with custom reactions) or `beberlei/doctrineextensions` (for DDD-style voting). However, Laravel Love stands out for its weighted system, custom reaction types, and enterprise-grade aggregation, making it ideal for complex use cases.