LaravelPackages.net
Acme Inc.
Toggle sidebar
roundly-consulting/likes-for-laravel

Lightweight Laravel package to handle likes on entities

423
5
2.1.0
About roundly-consulting/likes-for-laravel

roundly-consulting/likes-for-laravel is a Laravel package for lightweight laravel package to handle likes on entities. It currently has 5 GitHub stars and 423 downloads on Packagist (latest version 2.1.0). Install it with composer require roundly-consulting/likes-for-laravel. Discover more Laravel packages by roundly-consulting or browse all Laravel packages to compare alternatives.

Last updated

Likes for Laravel — Roundly open source

Latest release Tests Code style Donate Patreon Crypto

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 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.

Donate to Roundly open source Become a patron on Patreon Donate crypto: BTC, ETH, BNB or SOL

License

The MIT License (MIT). Please see License File for more information.

Comments
Affiliate link

Get paid by clients abroad

Wise gives you local bank details in several currencies and converts at the mid-market rate. Useful when your invoices are not in your own currency.

Try Wise

Star History Chart

Get the next ones by email

New Laravel packages worth a look, once a month. No spam, one-click unsubscribe.