giliomeejg/laravel-friendships
Composer 安装命令:
composer require giliomeejg/laravel-friendships
包简介
This package gives Eloquent models the ability to manage their friendships.
README 文档
README
This is a clone of hootlex/laravel-friendships that includes support for Laravel 5.8 as the original package does not seem to be maintained anymore.
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.
composer require giliomeejg/laravel-friendships
If you are using Laravel < 5.5, you need to add giliomeejg\Friendships\FriendshipsServiceProvider to your config/app.php providers array:
giliomeejg\Friendships\FriendshipsServiceProvider::class,
Publish config and migrations
php artisan vendor:publish --provider="giliomeejg\Friendships\FriendshipsServiceProvider"
Configure the published config in
config\friendships.php
Finally, migrate the database
php artisan migrate
Setup a Model
use giliomeejg\Friendships\Traits\Friendable; class User extends Model { use Friendable; ... }
How to use
Check 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);
Friends
To 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 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.
// 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 friendships by group you can pass a group slug.
$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.
giliomeejg/laravel-friendships 适用场景与选型建议
giliomeejg/laravel-friendships 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.31k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「friends」 「friendships」 「eloquent」 「friend-system」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 giliomeejg/laravel-friendships 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 giliomeejg/laravel-friendships 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 giliomeejg/laravel-friendships 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
This package gives Eloquent models the ability to manage their followers.
Alfabank REST API integration
This package gives Eloquent models the ability to manage their friendships.
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.
This package gives Eloquent models the ability to manage their friendships.
统计信息
- 总下载量: 2.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-09-26