| Number of watchers on Github | 420 |
| Number of open issues | 20 |
| Average time to close an issue | 15 days |
| Main language | PHP |
| Average time to merge a PR | 1 day |
| Open pull requests | 12+ |
| Closed pull requests | 6+ |
| Last commit | about 2 years ago |
| Repo Created | over 3 years ago |
| Repo Last Updated | over 1 year ago |
| Size | 116 KB |
| Organization / Author | hootlex |
| Latest Release | v1.0.23 |
| Contributors | 1 |
| Page Updated | 2018-03-12 |
| Do you use laravel-friendships? Leave a review! | |
| View open issues (20) | |
| View laravel-friendships activity | |
| View on github | |
| Fresh, new opensource launches 🚀🚀🚀 | |
|
Trendy new open source projects in your inbox!
View examples
|
|
This package gives Eloquent models the ability to manage their friendships. You can easily design a Facebook like Friend System.
First, install the package through Composer.
composer require hootlex/laravel-friendships
Then include the service provider inside config/app.php.
'providers' => [
...
Hootlex\Friendships\FriendshipsServiceProvider::class,
...
];
Publish config and migrations
php artisan vendor:publish --provider="Hootlex\Friendships\FriendshipsServiceProvider"
Configure the published config in
config\friendships.php
Finally, migrate the database
php artisan migrate
use Hootlex\Friendships\Traits\Friendable;
class User extends Model
{
use Friendable;
...
}
Check the Test file to see the package in action
$user->befriend($recipient);
$user->acceptFriendRequest($sender);
$user->denyFriendRequest($sender);
$user->unfriend($friend);
$user->blockFriend($friend);
$user->unblockFriend($friend);
$user->isFriendWith($friend);
$user->hasFriendRequestFrom($sender);
$user->hasSentFriendRequestTo($recipient);
$user->hasBlocked($friend);
$user->isBlockedBy($friend);
$user->getFriendship($friend);
$user->getAllFriendships();
$user->getPendingFriendships();
$user->getAcceptedFriendships();
$user->getDeniedFriendships();
$user->getBlockedFriendships();
$user->getFriendRequests();
$user->getFriendsCount();
$user->getMutualFriendsCount($otherUser);
To get a collection of friend models (ex. User) use the following methods:
$user->getFriends();
$user->getFriends($perPage = 20);
$user->getFriendsOfFriends($perPage = 20);
$user->getFriends($perPage = 20, $group_name);
$user->getMutualFriends($otherUser, $perPage = 20);
The friend groups are defined in the config/friendships.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.
// config/friendships.php
...
'groups' => [
'acquaintances' => 0,
'close_friends' => 1,
'family' => 2
]
Since you've configured friend groups, you can group/ungroup friends using the following methods.
$user->groupFriend($friend, $group_name);
$user->ungroupFriend($friend, 'family');
$user->ungroupFriend($friend);
$user->getFriendsCount($group_name);
friendships by group you can pass a group slug.$user->getAllFriendships($group_name);
$user->getAcceptedFriendships($group_name);
$user->getPendingFriendships($group_name);
...
This is the list of the events fired by default for each action
| Event name | Fired |
|---|---|
| friendships.sent | When a friend request is sent |
| friendships.accepted | When a friend request is accepted |
| friendships.denied | When a friend request is denied |
| friendships.blocked | When a friend is blocked |
| friendships.unblocked | When a friend is unblocked |
| friendships.cancelled | When a friendship is cancelled |
See the CONTRIBUTING guide.
Use complete namespace for Event
hasSentFriendRequestTo).