在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):hootlex/laravel-friendships开源软件地址(OpenSource Url):https://github.com/hootlex/laravel-friendships开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Laravel 5 FriendshipsThis package gives Eloquent models the ability to manage their friendships. You can easily design a Facebook like Friend System. Models can:
InstallationFirst, install the package through Composer. composer require hootlex/laravel-friendships If you are using Laravel < 5.5, you need to add Hootlex\Friendships\FriendshipsServiceProvider to your Hootlex\Friendships\FriendshipsServiceProvider::class, Publish config and migrations
Configure the published config in
Finally, migrate the database
Setup a Modeluse Hootlex\Friendships\Traits\Friendable;
class User extends Model
{
use Friendable;
...
} How to useCheck the Test file to see the package in action Send a Friend Request$user->befriend($recipient); Accept a Friend Request$user->acceptFriendRequest($sender); Deny a Friend Request$user->denyFriendRequest($sender); Remove Friend$user->unfriend($friend); Block a Model$user->blockFriend($friend); Unblock a Model$user->unblockFriend($friend); Check if Model is Friend with another Model$user->isFriendWith($friend); Check if Model has a pending friend request from another Model$user->hasFriendRequestFrom($sender); Check if Model has already sent a friend request to another Model$user->hasSentFriendRequestTo($recipient); Check if Model has blocked another Model$user->hasBlocked($friend); Check if Model is blocked by another Model$user->isBlockedBy($friend); Get a single friendship$user->getFriendship($friend); Get a list of all Friendships$user->getAllFriendships(); Get a list of pending Friendships$user->getPendingFriendships(); Get a list of accepted Friendships$user->getAcceptedFriendships(); Get a list of denied Friendships$user->getDeniedFriendships(); Get a list of blocked Friendships$user->getBlockedFriendships(); Get a list of pending Friend Requests$user->getFriendRequests(); Get the number of Friends$user->getFriendsCount(); Get the number of Pendings$user->getPendingsCount(); Get the number of mutual Friends with another user$user->getMutualFriendsCount($otherUser); FriendsTo get a collection of friend models (ex. User) use the following methods: Get Friends$user->getFriends(); Get Friends Paginated$user->getFriends($perPage = 20); Get Friends of Friends$user->getFriendsOfFriends($perPage = 20); Collection of Friends in specific group paginated:$user->getFriends($perPage = 20, $group_name); Get mutual Friends with another user$user->getMutualFriends($otherUser, $perPage = 20); Friend groupsThe friend groups are defined in the // 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. Group a Friend$user->groupFriend($friend, $group_name); Remove a Friend from family group$user->ungroupFriend($friend, 'family'); Remove a Friend from all groups$user->ungroupFriend($friend); Get the number of Friends in specific group$user->getFriendsCount($group_name);
To filter |
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.
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论