Download the PHP package edram/laravel-interactions without Composer
On this page you can find all versions of the php package edram/laravel-interactions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download edram/laravel-interactions
More information about edram/laravel-interactions
Files in edram/laravel-interactions
Package laravel-interactions
Short Description Laravel interactions package
License MIT
Homepage https://github.com/edram/laravel-interactions
Informations about the package laravel-interactions
Laravel Interactions
One polymorphic interaction system for likes, favorites, subscriptions, follows, votes, and custom actions.
AI skill
Install the package usage skill to give your coding agent the public APIs, setup rules, and examples from this repository:
Installation
Set the default actor model used by relations such as likers(), followers(), subscribers(), and voters():
The key_type configuration supports bigint, uuid, and ulid. Configure it before running the migration. Actors and interactables stored in the same interactions table must use the same key type.
Model setup
Actors use Interacts. Targets use Interactable. A model such as User that can both create and receive interactions uses both traits.
Both sides are polymorphic. A User, Team, or any other Eloquent model using Interacts can act on any model using Interactable.
For a smaller model API, combine the core concerns with only the semantic concerns the model needs:
Actor semantic concerns require HasInteractions. Target semantic concerns require ReceivesInteractions. Interacts and Interactable remain the convenient all-in-one alternatives.
Actor models
Any Eloquent model using Interacts, or HasInteractions with selected Actor concerns, can initiate interactions. default_actor is not an allowlist; it only chooses the related model when a target-side relation omits its Actor class.
A direct Eloquent relation returns one Actor model type. Query interaction records and eager load the polymorphic actor relation when all types are required:
When no Actor class is passed, the package resolves default_actor and then falls back to auth.providers.users.model. Pass the class explicitly to override either default.
Built-in interactions
| Interaction | Actor API | Target API |
|---|---|---|
| Like | like, unlike, toggleLike, hasLiked, likes, likedItems |
isLikedBy, likers, likersFor |
| Favorite | favorite, unfavorite, toggleFavorite, hasFavorited, favorites, favoriteItems |
isFavoritedBy, favoriters |
| Subscribe | subscribe, unsubscribe, toggleSubscribe, hasSubscribed, subscriptions, subscribedItems |
isSubscribedBy, subscribers |
| Follow | follow, unfollow, toggleFollow, isFollowing, following |
isFollowedBy, followers |
| Vote | vote, upvote, downvote, cancelVote, hasVoted, votes |
isVotedBy, voters, upvoters, downvoters, totalVotes |
like, favorite, subscribe, and follow are idempotent. Calling them repeatedly does not create duplicate records. A vote uses one record per actor and target; changing direction or weight updates that record.
To query a non-default actor model, pass its class explicitly:
Custom interactions
Custom action names are lowercase slugs up to 64 characters. Strings and string-backed enums are accepted.
Use the optional signed integer value for weighted actions and metadata for additional structured data.
Feed status
Attach several interaction states to a model, collection, or paginator with one interaction query:
null means no interaction exists, true means an interaction without a value exists, and an integer is the stored value.
Events and deletion
The package dispatches these events only when persistence actually changes:
Edram\LaravelInteractions\Events\InteractionCreatedEdram\LaravelInteractions\Events\InteractionUpdatedEdram\LaravelInteractions\Events\InteractionDeleted
Hard-deleting an actor or interactable removes its interactions. Soft deletion preserves them until the model is force deleted.
Development
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-interactions with dependencies
illuminate/contracts Version ^12.0 || ^13.0
illuminate/database Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0