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:
1$user1 = User::find(1);2$user2 = User::find(2);3 4$user1->befriend($user2);5$user2->acceptFriendRequest($user1);6 7// The messy breakup :(8$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:
1use Multicaret\Acquaintances\Traits\CanBeFollowed; 2use Multicaret\Acquaintances\Traits\CanFollow; 3use Multicaret\Acquaintances\Traits\CanLike; 4use Multicaret\Acquaintances\Traits\Friendable; 5//... 6 7class User extends Model 8{ 9 use Friendable;10 use CanLike;11 use CanFollow, CanBeFollowed;12 use CanRate, CanBeRated;13 //...14}
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.
0 comments:
Post a Comment
Thanks