Download the PHP package cjmellor/engageify without Composer
On this page you can find all versions of the php package cjmellor/engageify. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cjmellor/engageify
More information about cjmellor/engageify
Files in cjmellor/engageify
Package engageify
Short Description Easily add engagement features like likes, dislikes, upvotes, and downvotes to your models, paving the way for richer user interactions in your application
License MIT
Homepage https://github.com/cjmellor/engageify
Informations about the package engageify
Engageify is a Laravel package that allows you to integrate engagement features like user reactions (likes, upvotes) to your models.
Installation
You can install the package via composer:
Publish the config file (optional)
The published config file allows you to customize table names, model relationships, and more.
Usage
For Models you wish to have engagement features (likes/upvotes), use the Engageable trait.
Reactions
Allow Users to react to a Model.
An Event is run on each reaction occurrence.
ModelLikedEvent
ModelDislikedEvent
ModelUpvotedEvent
ModelDownvotedEvent
-
Multiple Reactions
By default, a User can only react once to a Model. If you wish to allow multiple reactions, you can do so by setting the engagement.allow_multiple_engagements
config value to true
.
"Like" Specific Reaction
The "like" reaction has some additional functionality. A "like" can be "unliked". This shouldn't be confused with a "dislike" as a "dislike" counts as an engagement, whereas an "unlike" is deleting the engagement.
When a Model is "unliked", an Event is fired.
There is also a convenient toggle()
method that will toggle between "like" and "unlike".
Fetch Engagements
Get the counts of the engagements.
Caching Engagement Counts
A caching feature is available, which is off by default but can be changed in the config file, or by adding it to your .env
file
When an engagement is retrieved, it is cached, and further requests will retireve the data from the cache.
On each new engagement, the cache will be cleared.
Fetch Users' Who Engaged
Instead of just fetching the amount of engagements, you can fetch the Users who engaged.
`
This will return a Collection of Users who liked the Model.
This works on all 4 fetch methods.
Events
Each engagement has an event that is fired when it occurs.
Here is an example of an Event when a Model is "liked". Each Event will return the same data
When a Model is "unliked", a ModelDisengagedEvent
is fired.
Testing
Changelog
Please see the CHANGELOG for more information on what has changed recently.
License
The MIT Licence (MIT). Please see LICENSE for more information.