百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-friendships

> 后端框架
开源

此包使 Eloquent 模型能够管理它们的友谊关系。

700 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

此包使 Eloquent 模型能够管理它们的友谊关系。

Laravel 5 Friendships

This package gives Eloquent models the ability to manage their friendships. You can easily design a Facebook like Friend System.

Models can:

  • Send Friend Requests
  • Accept Friend Requests
  • Deny Friend Requests
  • Block Another Model
  • Group Friends

Installation

First, install the package through Composer.

php
composer require hootlex/laravel-friendships

If you are using Laravel befriend($recipient);


#### Accept a Friend Request
```php
$user->acceptFriendRequest($sender);

Deny a Friend Request

php
$user->denyFriendRequest($sender);

Remove Friend

php
$user->unfriend($friend);

Block a Model

php
$user->blockFriend($friend);

Unblock a Model

php
$user->unblockFriend($friend);

Check if Model is Friend with another Model

php
$user->isFriendWith($friend);

Check if Model has a pending friend request from another Model

php
$user->hasFriendRequestFrom($sender);

Check if Model has already sent a friend request to another Model

php
$user->hasSentFriendRequestTo($recipient);

Check if Model has blocked another Model

php
$user->hasBlocked($friend);

Check if Model is blocked by another Model

php
$user->isBlockedBy($friend);

Get a single friendship

php
$user->getFriendship($friend);

Get a list of all Friendships

php
$user->getAllFriendships();

Get a list of pending Friendships

php
$user->getPendingFriendships();

Get a list of accepted Friendships

php
$user->getAcceptedFriendships();

Get a list of denied Friendships

php
$user->getDeniedFriendships();

Get a list of blocked Friendships

php
$user->getBlockedFriendships();

Get a list of pending Friend Requests

php
$user->getFriendRequests();

Get the number of Friends

php
$user->getFriendsCount();

Get the number of Pendings

php
$user->getPendingsCount();

Get the number of mutual Friends with another user

php
$user->getMutualFriendsCount($otherUser);

Friends

To get a collection of friend models (ex. User) use the following methods:

Get Friends

php
$user->getFriends();

Get Friends Paginated

php
$user->getFriends($perPage = 20);

Get Friends of Friends

php
$user->getFriendsOfFriends($perPage = 20);

Collection of Friends in specific group paginated:

php
$user->getFriends($perPage = 20, $group_name);

Get mutual Friends with another user

php
$user->getMutualFriends($otherUser, $perPage = 20);

Friend groups

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.

php
// 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

php
$user->groupFriend($friend, $group_name);

Remove a Friend from family group

php
$user->ungroupFriend($friend, 'family');

Remove a Friend from all groups

php
$user->ungroupFriend($friend);

Get the number of Friends in specific group

php
$user->getFriendsCount($group_name);

To filter friendships by group you can pass a group slug.

php
$user->getAllFriendships($group_name);
$user->getAcceptedFriendships($group_name);
$user->getPendingFriendships($group_name);
...

Events

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

Contributing

See the CONTRIBUTING guide.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPeloquentfriend-groupsfriend-requestsfriendships

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架