ritechoice23/laravel-reactions
Laravel Reactions adds likes, loves, and other reactions to any Eloquent model. Attach reactions to posts, comments, or custom models, support multiple reaction types, and customize behavior with a simple API for building more engaging Laravel applications.
composer require ritechoice23/laravel-reactions.php artisan vendor:publish --tag=laravel-reactions-config
php artisan vendor:publish --tag=laravel-reactions-migrations
php artisan migrate
like, love, celebrate, etc. Treat these strings as part of your public API contract.Post, Comment, Video. Add the reactor trait to the model that reacts, usually User.react / unreact / toggle methods exposed by 1.0.0.$data = $request->validate([
'type' => ['required', Rule::in(config('reactions.types'))],
]);
$post->toggleReaction($data['type'], $request->user());
return response()->json([
'counts' => $post->reactionCounts(),
'mine' => $post->reactionFor($request->user()),
]);
Verify exact method names against the installed package; at 1.0.0 these are the primary public surface you will use day to day.return [
'id' => $post->id,
'reactions' => [
'counts' => $post->reactionCounts(),
'mine' => $post->reactionFor(auth()->user()),
],
];
/posts/{post}/reactions/{type}.PostReacted, PostReactionRemoved, or your own wrapper event. Use these for notifications, activity feeds, and analytics without blocking the request with heavy work.^1.0 until you have a reason to move.reactable_type, reactable_id, reactor ID, and reaction type.$post->reactions->count() inside a loop causes N+1 queries; use the package’s count helper or a database aggregate.php artisan config:clear. In production, deploy config changes deliberately.like to thumbs_up later is a breaking client change.How can I help you explore Laravel packages today?