cybercog/laravel-likeable
Add like and dislike functionality to Laravel Eloquent models via a polymorphic many-to-many relationship. Includes reusable traits, query scopes, and events, letting users quickly like or dislike posts, comments, and any other model.
Architecture fit. cybercog/laravel-likeable is a trait-based, polymorphic many-to-many implementation (a Likeable trait plus a morph pivot table) that maps cleanly onto standard Eloquent conventions. It introduces no new infrastructure — only a migration and a trait — so it slots into an existing Laravel domain model without architectural negotiation. Release 3.1.0 does not change the public API or schema; it changes the resolution strategy inside the "is this model liked by this user" check to consult eager-loaded relations before issuing a query.
Integration feasibility. Low effort. composer require, publish/run the migration, add the trait to target models, and the like/unlike/check surface is available immediately. 3.1.0 is a drop-in from 3.0.1 — no migration, config, or namespace changes.
Technical risk. Low but non-zero, and concentrated entirely in the 3.1.0 behavioral change. Preferring eager-loaded relations means correctness now depends on relation freshness: if a collection was loaded before a like/unlike mutation in the same request lifecycle, the check may return a stale answer. The fallback path (query when the relation is not loaded) preserves prior behavior, so risk is scoped to endpoints that already eager-load likes. Upside is real: this is the difference between N queries and 1 for feed/listing endpoints that render liked-state per row.
Key questions.
(user_id, likeable_type, likeable_id), or is duplicate-like prevention our responsibility?like() / toggle() return semantics or event dispatching change under the new path?Stack fit. Standard Laravel (Eloquent, migrations, service container) with MySQL/Postgres/SQLite. No queue, cache, or external service dependency. Composes with API Resources, policies, and query scopes without adaptation.
Migration path. From 3.0.1: composer update cybercog/laravel-likeable and run the existing suite — nothing else. From 2.x: treat as a separate, reviewed change (2.x→3.x carries the package's own upgrade notes); do not bundle it with the 3.1.0 bump.
Compatibility. Semver-minor, no breaking changes, no deprecations. Pin to ^3.1 so the eager-load optimization is guaranteed present. Verify the framework constraint in composer.json against each consuming app before rollout.
Sequencing.
with('likes') (or an equivalent scoped eager load) in the listing/feed endpoints that read liked-state — this is where 3.1.0 actually pays off.Maintenance. Small surface area (one trait, one table, a handful of methods), so ongoing maintenance is near-zero. The dominant risk is upstream stewardship, not code complexity — confirm release cadence; if activity is thin, budget for a vendored fork.
Support. Community GitHub issues only; no vendor SLA. Internal ownership should be assigned to whoever owns the Laravel platform layer. Keep the version pin explicit so an unexpected upstream release cannot change query behavior silently.
Scaling. This release is a net scaling win: liked-state checks across collections drop from O(n) queries to a constant number when relations are eager-loaded. The pivot table remains the long-term scaling concern — ensure a composite index on (likeable_type, likeable_id, user_id) and a uniqueness constraint to prevent duplicate rows under concurrent requests.
Failure modes.
likeable_type strings, silently orphaning existing likes.Ramp-up. Roughly a day for a mid-level Laravel developer to integrate and test; half a day more to retrofit eager loading into existing read paths and codify the freshness convention. No specialized knowledge required.
How can I help you explore Laravel packages today?