roundly-consulting / likes-for-laravel
Lightweight Laravel package to handle likes on entities
Package info
github.com/roundly-consulting/likes-for-laravel
pkg:composer/roundly-consulting/likes-for-laravel
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/broadcasting: ^12.0|^13.0
- illuminate/contracts: ^12.0|^13.0
- illuminate/database: ^12.0|^13.0
- illuminate/http: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- roundly-consulting/package-toolkit-for-laravel: ^1.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.1.1
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-laravel: ^4.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^2.0
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Likes for Laravel
Likes and reactions for any Eloquent model: any model can give likes, any model can receive them,
and one polymorphic likes table records who liked what. Typed reactions, popularity and trending
scopes, single-query feed hydration and reaction breakdowns come on top.
Installation
Requires PHP 8.4 and Laravel 12 or 13.
composer require roundly-consulting/likes-for-laravel
php artisan vendor:publish --tag="likes-migrations"
php artisan migrate
If your actors or likeable models have UUID/ULID keys, set LIKES_KEY_TYPE before migrating.
Usage
Let models give and receive likes:
use Illuminate\Database\Eloquent\Model; use RoundlyConsulting\Likes\Traits\GivesLikes; use RoundlyConsulting\Likes\Traits\HasLikes; class Post extends Model { use HasLikes; } class User extends Model { use GivesLikes; }
Like and read through the facade — the actor defaults to the authenticated user:
use RoundlyConsulting\Likes\Facades\Likes; Likes::like($post); // true — liked now; liking again is a no-op Likes::toggle($comment); // the resulting state Likes::actor($team)->like($post); // as any other actor Likes::for($post)->count(); // int Likes::for($post)->likedBy($user); // bool Likes::for($post)->summary(); // ReactionSummary: total, counts, top, viewer's reaction
Render a feed with the viewer's state in a single query:
$posts = Post::query() ->withLikedState() // is_liked + liked_reaction for the viewer ->withLikesCount() // likes_count — still one query ->latest() ->paginate();
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/likes-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). Please see License File for more information.