What an actor liked
Reverse the relation to list what an actor likes:
$user->likedItems(Post::class)->get(); // posts the user actively likes
$user->likedItems(Post::class, 'love')->get(); // filtered by reaction
$user->likedItems(Post::class)->with('author')->paginate(); // real relation — eager-load & paginate
$user->likesOf(Post::class); // the underlying MorphToMany relationlikedItems() returns a real Eloquent relation, so constraints, eager loading and pagination work as usual. Soft-deleted (unliked) items drop out automatically and reappear on a re-like.
The reaction on the pivot
The relation carries the reaction type on its pivot:
foreach ($user->likedItems(Post::class)->get() as $post) {
$post->pivot->type; // the actor's earliest active reaction on it (or the filtered type)
}Each item comes back once, however many reactions the actor left on it, and paginate()->total() counts items, not reactions. The pivot’s type is the actor’s earliest active reaction on the item, or the requested type when you filter by one.
For the opposite list — items an actor has not liked — use the whereNotLikedBy() scope on the likeable model.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.