### Install and publish migrations Source: https://github.com/roundly-consulting/likes-for-laravel/blob/main/README.md Install the package via Composer, publish the migrations, and run them. Requires PHP 8.4 and Laravel 12 or 13. Set LIKES_KEY_TYPE before migrating if your models use UUID/ULID keys. ```bash composer require roundly-consulting/likes-for-laravel php artisan vendor:publish --tag="likes-migrations" php artisan migrate ``` -------------------------------- ### Query posts with liked state and counts Source: https://github.com/roundly-consulting/likes-for-laravel/blob/main/README.md Use withLikedState() and withLikesCount() to fetch posts with the viewer's liked state and like counts in a single query. This example chains them with latest() and paginate(). ```php $posts = Post::query() ->withLikedState() // is_liked + liked_reaction for the viewer ->withLikesCount() // likes_count — still one query ->latest() ->paginate(); ``` -------------------------------- ### Like, toggle, and query via the Likes facade Source: https://github.com/roundly-consulting/likes-for-laravel/blob/main/README.md Use the Likes facade to like, toggle, and query likes. The actor defaults to the authenticated user. Methods return booleans, integers, or a ReactionSummary object. ```php 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 ``` -------------------------------- ### Add HasLikes and GivesLikes traits to models Source: https://github.com/roundly-consulting/likes-for-laravel/blob/main/README.md Use the HasLikes trait on models that receive likes and the GivesLikes trait on models that give likes. Both traits are applied to Eloquent models. ```php 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; } ```