Manage Friendships, Likes and More with the Acquaintances Laravel Package
Published on by Paul Redmond
The multicaret/laravel-acquaintances package gives eloquent models the ability to manage friendships, groups, followers, likes, ratings, and favorites.
Related: Add Social Reactions to Model with Laravel Love
Here’s a basic example from the readme:
$user1 = User::find(1);$user2 = User::find(2); $user1->befriend($user2);$user2->acceptFriendRequest($user1); // The messy breakup :($user2->unfriend($user1);
Out of the box, you can expect the following features (features may change over time):
- Send Friend Requests
- Accept Friend Requests
- Deny Friend Requests
- Block a User
- Group Friends
- Rate a User or a Model, supporting multiple aspects
- Follow a User or a Model
- Like a User or a Model
- Subscribe a User or a Model
- Favorite a User or a Model
- Vote (Upvote & Downvote a User or a Model)
The package has several traits you can use to define capabilities on a model. Here’s a bunch of them defined on a User
model:
use Multicaret\Acquaintances\Traits\CanBeFollowed;use Multicaret\Acquaintances\Traits\CanFollow;use Multicaret\Acquaintances\Traits\CanLike;use Multicaret\Acquaintances\Traits\Friendable;//... class User extends Model{ use Friendable; use CanLike; use CanFollow, CanBeFollowed; use CanRate, CanBeRated; //...}
The project’s readme has all the details for each model interaction and contains quite a few useful features. You can learn more about this project on GitHub at multicaret/laravel-acquaintances.