Download the PHP package elemenx/laravel-acquaintances without Composer
On this page you can find all versions of the php package elemenx/laravel-acquaintances. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elemenx/laravel-acquaintances
More information about elemenx/laravel-acquaintances
Files in elemenx/laravel-acquaintances
Package laravel-acquaintances
Short Description This light package, with no dependencies, gives Eloquent models the ability to manage friendships (with groups). And interactions such as: Likes, favorites, votes, subscribe, follow, ..etc. And it includes advanced rating system.
License MIT
Rated 5.00 based on 1 reviews
Informations about the package laravel-acquaintances
Laravel Acquaintances
Supports Laravel 8 and below, with no dependencies
TL;DR
Gives eloquent models:
- Friendships & Groups ability
- Interactions ability such as:
- Likes
- Favorites
- Votes (up/down)
- Subscribe
- Follow
- Ratings
Take this example:
- Introduction
- Installation
- Friendships:
- Friend Requests
- Check Friend Requests
- Retrieve Friend Requests
- Retrieve Friends
- Friend Groups
- Interactions
- Traits Usage
- Follow
- Rate
- Like
- Favorite
- Subscribe
- Vote
- Parameters
- Query relations
- Working with model
- Events
- Contributing
Introduction
This light package gives Eloquent models the ability to manage their acquaintances and other cool useful stuff. You can easily design your social-like System (Facebook, Twitter, Foursquare...etc).
Acquaintances includes:
- 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)
Installation
First, install the package through Composer.
Laravel 5.8 and up => version 2.x (branch master)
Laravel 5.7 and below => version 1.x (branch v1)
Laravel 5.4 and down
Then include the service provider inside config/app.php
.
Publish config and migrations:
Configure the published config in:
Finally, migrate the database to create the table:
Setup a Model
Example:
All available APIs are listed below for Friendships & Interactions.
Friendships:
Friend Requests:
Add Friendable
Trait to User model.
Send a Friend Request
Accept a Friend Request
Deny a Friend Request
Remove Friend
Block a Model
Unblock a Model
Check if Model is Friend with another Model
Check Friend Requests:
Check if Model has a pending friend request from another Model
Check if Model has already sent a friend request to another Model
Check if Model has blocked another Model
Check if Model is blocked by another Model
Retrieve Friend Requests:
Get a single friendship
Get a list of all Friendships
Get a list of pending Friendships
Get a list of accepted Friendships
Get a list of denied Friendships
Get a list of blocked Friendships
Get a list of pending Friend Requests
Get the number of Friends
Get the number of Pending Requests
Get the number of mutual Friends with another user
Retrieve Friends:
To get a collection of friend models (ex. User) use the following methods:
getFriends()
Parameters:
$perPage
: integer (default:0
), Get values paginated$group_name
: string (default:''
), Get collection of Friends in specific group paginated$fields
: array (default:['*']
), Specify the desired fields to query.
getFriendsOfFriends()
Parameters:
$perPage
: integer (default:0
), Get values paginated$fields
: array (default:['*']
), Specify the desired fields to query.
getMutualFriends()
Get mutual Friends with another user
Parameters:
$other
: Model (required), The Other user model to check mutual friends with$perPage
: integer (default:0
), Get values paginated$fields
: array (default:['*']
), Specify the desired fields to query.
Friend Groups:
The friend groups are defined in the config/acquaintances.php
file. The package comes with a few default groups. To
modify them, or add your own, you need to specify a slug
and a key
.
Since you've configured friend groups, you can group/ungroup friends using the following methods.
Group a Friend
Remove a Friend from family group
Remove a Friend from all groups
Get the number of Friends in specific group
To filter friendships
by group you can pass a group slug.
Interactions
Traits Usage:
Add CanXXX
Traits to User model.
Add CanBeXXX
Trait to target model, such as 'Post' or 'Book' ...:
All available APIs are listed below.
Follow
\ElemenX\Acquaintances\Traits\CanFollow
\ElemenX\Acquaintances\Traits\CanBeFollowed
Rate
\ElemenX\Acquaintances\Traits\CanRate
\ElemenX\Acquaintances\Traits\CanBeRated
Like
\ElemenX\Acquaintances\Traits\CanLike
\ElemenX\Acquaintances\Traits\CanBeLiked
Favorite
\ElemenX\Acquaintances\Traits\CanFavorite
\ElemenX\Acquaintances\Traits\CanBeFavorited
Subscribe
\ElemenX\Acquaintances\Traits\CanSubscribe
ElemenX\Acquaintances\Traits\CanBeSubscribed
Vote
\ElemenX\Acquaintances\Traits\CanVote
\ElemenX\Acquaintances\Traits\CanBeVoted
Parameters
All the above mentioned methods of creating relationships, such as 'follow', 'like', 'unfollow', 'unlike', their syntax is as follows:
So you can call them like this:
Query relations
You may use the others in the same way.
Working with model
Events
This is the list of the events fired by default for each action:
Event name | Fired |
---|---|
acq.friendships.sent | When a friend request is sent |
acq.friendships.accepted | When a friend request is accepted |
acq.friendships.denied | When a friend request is denied |
acq.friendships.blocked | When a friend is blocked |
acq.friendships.unblocked | When a friend is unblocked |
acq.friendships.cancelled | When a friendship is cancelled |
acq.ratings.rate | When a an item or items get Rated |
acq.ratings.unrate | When a an item or items get unRated |
acq.vote.up | When a an item or items get upvoted |
acq.vote.down | When a an item or items get downvoted |
acq.vote.cancel | When a an item or items get vote cancellation |
acq.likes.like | When a an item or items get liked |
acq.likes.unlike | When a an item or items get unliked |
acq.followships.follow | When a an item or items get followed |
acq.followships.unfollow | When a an item or items get unfollowed |
acq.favorites.favorite | When a an item or items get favored |
acq.favorites.unfavorite | When a an item or items get unfavored |
acq.subscriptions.subscribe | When a an item or items get subscribed |
acq.subscriptions.unsubscribe | When a an item or items get unsubscribed |
Contributing
See the CONTRIBUTING guide.
The initial version of this library was assisted by the following repos laravel-friendships & laravel-follow.
Change Log
See the log file.